pjfanning opened a new pull request, #2743: URL: https://github.com/apache/pekko/pull/2743
Port of <a href="https://github.com/akka/akka-core/pull/31695">akka/akka-core#31695</a>. Reduces heap allocations in `PropsAdapter.apply` (called on every typed actor spawn) and adds the accompanying test coverage. part of #2730 ## PropsAdapter optimizations (`PropsAdapter.scala`) - **`DefaultTypedDeploy` constant** — pre-built `Deploy` (local scope + typed default mailbox) reused across calls instead of reconstructed each time - **`TypedCreatorFunctionConsumerClazz` constant** — cached class reference - **Build `Deploy` directly** — replaces chained `.withDispatcher()` / `.withMailbox()` / `.withDeploy()` calls (each producing a new `Props` copy) with direct `.copy()` on `Deploy` - **Fast-path for `Props.empty`** — skips all matching logic and reuses `DefaultTypedDeploy` directly for the common no-custom-props case - **Direct `Props` constructor** — uses `new pekko.actor.Props(deploy, clazz, args)` to bypass factory methods and avoid extra intermediate copies ## Props caching (`CachedProps.scala`, `Behavior.scala`, `ActorRefFactoryAdapter.scala`) - **`CachedProps.scala`** (new) — internal case class holding a cached typed→classic Props mapping - **`Behavior.scala`** — adds `_internalClassicPropsCache` volatile field to `Behavior[T]` so each behavior instance can cache its last adapted classic `Props` - **`ActorRefFactoryAdapter.scala`** — adds `classicPropsFor` helper that checks the behavior's cache before adapting props, avoiding repeated work when spawning many actors of the same type with the same props ## Additional optimizations - **`ActorContextAdapter.scala`** — lazy `_self` field: `ActorRefAdapter` is not allocated unless `self` is actually accessed - **`ActorAdapter.scala`** — `val supervisorStrategy` → `final override def supervisorStrategy` to avoid per-instance field allocation ## Test coverage (`PropsAdapterSpec.scala`) Added tests covering all `PropsAdapter` code paths: - `MailboxSelector.defaultMailbox()` → `"pekko.actor.typed.default-mailbox"` - `withDispatcherFromConfig("some.path")` → dispatcher `"some.path"` - `withDispatcherSameAsParent` → dispatcher `".."` - `MailboxSelector.fromConfig("some.path")` → mailbox `"some.path"` - `MailboxSelector.bounded(24)` → mailbox `"bounded-capacity:24"` - `ActorTags.create("my-tag")` → `deploy.tags == Set("my-tag")` -- 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]
