Avoid receive timeout type pollution#3332
Open
He-Pin wants to merge 4 commits into
Open
Conversation
He-Pin
force-pushed
the
perf/1668-actor-receive-timeout
branch
2 times, most recently
from
July 14, 2026 04:11
3838449 to
8ce7dbc
Compare
pjfanning
reviewed
Jul 18, 2026
| import scala.concurrent.Await | ||
| import scala.concurrent.duration._ | ||
|
|
||
| import org.apache.pekko.actor.dungeon.{ ReceiveTimeout => ReceiveTimeoutSupport } |
Member
There was a problem hiding this comment.
can you rebase and fix the imports to be pekko.?
pjfanning
reviewed
Jul 18, 2026
|
|
||
| // Identify is also an AutoReceivedMessage. Checking its concrete class first avoids polluting its secondary | ||
| // supertype cache on JDKs affected by JDK-8180450 when actor runtime code also checks the AutoReceivedMessage marker. | ||
| @inline def isNotInfluenceReceiveTimeout(message: Any): Boolean = |
Member
There was a problem hiding this comment.
@inline doesn't work for Scala 3. You might need to create a Scala 2 and Scala 3 file with just this method. Better than copy/pasting this whole scala file.
Motivation: The ActorCell receive timeout path allocates on every message and misclassifies timer messages, causing unnecessary timeout rescheduling and state churn. Modification: - Avoid type pollution in the receive timeout hot path - Guard timer receive timeout classification Result: Reduced allocations and correct timeout behavior for actors using receive timeouts. Tests: - Existing ActorCellReceiveTimeoutSpec References: Refs apache#1668
Motivation: The @inline annotation does not work for Scala 3. The JVM JIT will inline this small method regardless of the annotation. Modification: Remove the @inline annotation from isNotInfluenceReceiveTimeout method. Result: Code compiles cleanly on both Scala 2.13 and Scala 3. Performance is unaffected as the JIT compiler will still inline the method. Tests: Not run - annotation removal only, no behavior change References: Refs apache#3332
He-Pin
force-pushed
the
perf/1668-actor-receive-timeout
branch
from
July 20, 2026 03:59
3495f33 to
944ff2e
Compare
Motivation: The @inline annotation does not work for Scala 3. Reviewer requested splitting the method into version-specific files to preserve the inline optimization for Scala 2 while supporting Scala 3. Modification: - Create ReceiveTimeoutCompat object in scala-2.13 with @inline annotation - Create ReceiveTimeoutCompat object in scala-3 with inline keyword - Move isNotInfluenceReceiveTimeout method from ReceiveTimeout to ReceiveTimeoutCompat - Update all call sites to use ReceiveTimeoutCompat Result: Code compiles cleanly on both Scala 2.13 and Scala 3 with appropriate inline optimizations for each version. Tests: sbt "actor-tests/Test/testOnly org.apache.pekko.actor.ReceiveTimeoutSpec" All 14 tests passed. References: Refs apache#3332
Motivation: The isNotInfluenceReceiveTimeout method was moved from ReceiveTimeout to ReceiveTimeoutCompat in the version-specific files, but two call sites still referenced the old location, causing compilation failures across all CI jobs. Modification: Update TimerSchedulerImpl (actor-typed) and ReceiveTimeoutTypePollutionBenchmark (bench-jmh) to reference ReceiveTimeoutCompat.isNotInfluenceReceiveTimeout. Result: All modules compile successfully on both Scala 2.13 and Scala 3. Tests: - sbt "actor-typed / Compile / compileIncremental" (Scala 2.13) - success - sbt "++3.3.8; actor-typed / Compile / compileIncremental" - success References: Refs apache#3332
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Identifyimplements bothAutoReceivedMessageandNotInfluenceReceiveTimeout. On JVMs affected by JDK-8180450, alternating successful checks against those two secondary supertypes makes the same concreteKlasssecondary-super cache ping-pong between marker types. The checks occur on the Actor receive-timeout path and can contend across actor-dispatcher threads.The receive path also classified the same message against
NotInfluenceReceiveTimeouttwice.Modification
Identifywith a concrete-class guard before theNotInfluenceReceiveTimeoutmarker check.Result
Receive-timeout behavior remains unchanged, while
Identifyno longer alternates the concrete class secondary-super cache between its two marker interfaces. The final path also performs one classification instead of two.JMH throughput (
ops/us, 12 threads, 3 forks, 5 x 1 s warmup and measurement iterations):JDK 21.0.8 and JDK 25 contain the JVM fix, so their remaining gain primarily measures the removed classification/call rather than secondary-super-cache contention. The JDK 25 result was noisier than the other runs.
References
Refs #1668