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

   ### Motivation
   
   An actor with receive timeout enabled currently recreates immutable 
`(Duration, Cancellable)` tuples while cancelling and rescheduling the timeout 
for every influencing message. This puts two short-lived `Tuple2` objects on 
the `ActorCell.invoke` hot path even though receive-timeout state is 
mailbox-thread confined.
   
   This is logically independent from #3332. Both PRs touch 
`ReceiveTimeout.scala`, so whichever merges second will need a small rebase, 
but this branch does not include the type-pollution change.
   
   ### Modification
   
   - Replace tuple replacement with one lazily allocated mutable 
receive-timeout state object.
   - Track state changes with an `Int` counter compared only across one message 
invocation, preserving the previous tuple-reference identity semantics without 
per-message state allocation.
   - Extend `ReceiveTimeoutSpec` with a 100-message reset burst and an explicit 
assertion that the timeout is measured from the final processed message.
   - Add an end-to-end Actor JMH benchmark that processes real mailbox messages 
while receive timeout is active and supports the JMH GC profiler.
   
   ### Result
   
   JDK 17.0.17, G1, one Actor/dispatcher thread, 10,000 messages per 
invocation, 3 forks, 5 x 1 second warmup and measurement:
   
   | Implementation | Throughput | Steady allocation |
   | --- | ---: | ---: |
   | Immutable tuple state | 16.049 ± 1.323 messages/µs | 168.018 B/message |
   | Reused mutable state | 16.476 ± 1.825 messages/µs | 120.018 B/message |
   
   The allocation result is stable across all non-teardown measurement 
iterations: exactly 48 B/message less, a 28.6% reduction in total allocation 
for this real Actor path. Throughput confidence intervals overlap, so this PR 
claims allocation/GC improvement rather than a statistically significant CPU 
improvement.
   
   The state object is allocated only when an actor first configures receive 
timeout; actors that never enable it retain the existing null-reference 
footprint. Public Actor APIs and behavior are unchanged.
   
   ### Tests
   
   - `sbt "actor-tests / Test / testOnly 
org.apache.pekko.actor.ReceiveTimeoutSpec"` — passed, 13 tests
   - `sbt "bench-jmh / Jmh / compile"` — passed
   - `ReceiveTimeoutBenchmark -prof gc` on Azul JDK 17.0.17 — completed; 
results above
   - `sbt +mimaReportBinaryIssues` — passed on Scala 2.13 and Scala 3
   - `sbt "+headerCheckAll" checkCodeStyle` — passed
   - Native scalafmt diff check — passed
   - `git diff --check` — passed
   - Qoder stdout review — No must-fix findings
   - `sbt validatePullRequest` — not completed locally per request; rely on CI
   
   ### References
   
   Refs #1668
   
   - Related type-pollution fix: #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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to