You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "He-Pin (via GitHub)" <gi...@apache.org> on 2026/07/11 19:05:04 UTC

[PR] Avoid receive timeout type pollution [pekko]

He-Pin opened a new pull request, #3332:
URL: https://github.com/apache/pekko/pull/3332

   ### Motivation
   
   `Identify` implements both `AutoReceivedMessage` and `NotInfluenceReceiveTimeout`. On JVMs affected by [JDK-8180450](https://bugs.openjdk.org/browse/JDK-8180450), alternating successful checks against those two secondary supertypes makes the same concrete `Klass` secondary-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 `NotInfluenceReceiveTimeout` twice.
   
   ### Modification
   
   - Classify final `Identify` with a concrete-class guard before the `NotInfluenceReceiveTimeout` marker check.
   - Return the pre-cancellation timeout state and infer the post-receive reschedule decision from the state transition, removing the second marker check.
   - Add focused classification coverage.
   - Add a 12-thread JMH benchmark for the polluted, concrete-guarded, and final production-shaped paths.
   
   ### Result
   
   Receive-timeout behavior remains unchanged, while `Identify` no 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):
   
   | Runtime | Polluted path | Concrete guard | Final path | Final / polluted |
   | --- | ---: | ---: | ---: | ---: |
   | JDK 17.0.17 | 824.700 +/- 10.066 | 1633.766 +/- 53.719 | 2205.529 +/- 92.313 | 2.67x |
   | JDK 21.0.8 | 1125.827 +/- 16.496 | 1609.084 +/- 31.694 | 2158.924 +/- 36.895 | 1.92x |
   | JDK 25.0.2 | 1717.703 +/- 77.349 | 1841.141 +/- 53.279 | 2467.700 +/- 262.562 | 1.44x |
   
   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.
   
   ### Tests
   
   - `sbt "actor-tests / Test / testOnly org.apache.pekko.actor.ReceiveTimeoutSpec"` - passed, 14 tests
   - `sbt "bench-jmh / Jmh / compile"` - passed
   - `scalafmt --list --mode diff-ref=origin/main` - passed
   - `sbt "+headerCheckAll" checkCodeStyle` - passed
   - `sbt +mimaReportBinaryIssues` - passed for Scala 2.13 and 3
   - `git diff --check` - passed
   - `sbt validatePullRequest` - ran for 26m49s; the changed Actor core expanded validation across dependent modules. It reported unrelated baseline/platform failures:
     - `TcpConnectionSpec` timed out under the full concurrent run; focused rerun passed all 35 executed tests.
     - `NettyTransportSpec` cannot bind `127.0.1.1` on this macOS host.
     - `JournalNoCompactionSpec` loads an x86-only LevelDB JNI library on this arm64 host and the fork exits with 255; the other 54 persistence tests passed.
     - `IntegrationDocTest` references `pekko.dispatch.UnboundedMailbox`; the same value is present on `origin/main` and fails with `ClassNotFoundException`.
     - the remote Multi-JVM aggregate ended with `No tests to run for MultiJvm` after executing its individual specs.
   - Qoder stdout review - No must-fix findings
   
   ### References
   
   Refs #1668
   
   - [JDK-8180450](https://bugs.openjdk.org/browse/JDK-8180450)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] Avoid receive timeout type pollution [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #3332:
URL: https://github.com/apache/pekko/pull/3332#discussion_r3609370604


##########
actor/src/main/scala/org/apache/pekko/actor/dungeon/ReceiveTimeout.scala:
##########
@@ -19,10 +19,16 @@ import scala.concurrent.duration.FiniteDuration
 import org.apache.pekko
 import pekko.actor.ActorCell
 import pekko.actor.Cancellable
+import pekko.actor.Identify
 import pekko.actor.NotInfluenceReceiveTimeout
 
 private[pekko] object ReceiveTimeout {
   final val emptyReceiveTimeoutData: (Duration, Cancellable) = (Duration.Undefined, ActorCell.emptyCancellable)
+
+  // 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 =

Review 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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] Avoid receive timeout type pollution [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #3332:
URL: https://github.com/apache/pekko/pull/3332#discussion_r3609367382


##########
actor-tests/src/test/scala/org/apache/pekko/actor/ReceiveTimeoutSpec.scala:
##########
@@ -20,6 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger
 import scala.concurrent.Await
 import scala.concurrent.duration._
 
+import org.apache.pekko.actor.dungeon.{ ReceiveTimeout => ReceiveTimeoutSupport }

Review Comment:
   can you rebase and fix the imports to be `pekko.`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] Avoid receive timeout type pollution [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin merged PR #3332:
URL: https://github.com/apache/pekko/pull/3332


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] Avoid receive timeout type pollution [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #3332:
URL: https://github.com/apache/pekko/pull/3332#discussion_r3609374777


##########
actor-tests/src/test/scala/org/apache/pekko/actor/ReceiveTimeoutSpec.scala:
##########
@@ -20,6 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger
 import scala.concurrent.Await
 import scala.concurrent.duration._
 
+import org.apache.pekko.actor.dungeon.{ ReceiveTimeout => ReceiveTimeoutSupport }

Review Comment:
   I pushed a fix for this



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org