Optimize PropsAdapter + add test coverage#2743
Open
pjfanning wants to merge 5 commits intoapache:mainfrom
Open
Optimize PropsAdapter + add test coverage#2743pjfanning wants to merge 5 commits intoapache:mainfrom
pjfanning wants to merge 5 commits intoapache:mainfrom
Conversation
…-core#31695) Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
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.
Port of akka/akka-core#31695. 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)DefaultTypedDeployconstant — pre-builtDeploy(local scope + typed default mailbox) reused across calls instead of reconstructed each timeTypedCreatorFunctionConsumerClazzconstant — cached class referenceDeploydirectly — replaces chained.withDispatcher()/.withMailbox()/.withDeploy()calls (each producing a newPropscopy) with direct.copy()onDeployProps.empty— skips all matching logic and reusesDefaultTypedDeploydirectly for the common no-custom-props casePropsconstructor — usesnew pekko.actor.Props(deploy, clazz, args)to bypass factory methods and avoid extra intermediate copiesProps caching (
CachedProps.scala,Behavior.scala,ActorRefFactoryAdapter.scala)CachedProps.scala(new) — internal case class holding a cached typed→classic Props mappingBehavior.scala— adds_internalClassicPropsCachevolatile field toBehavior[T]so each behavior instance can cache its last adapted classicPropsActorRefFactoryAdapter.scala— addsclassicPropsForhelper that checks the behavior's cache before adapting props, avoiding repeated work when spawning many actors of the same type with the same propsAdditional optimizations
ActorContextAdapter.scala— lazy_selffield:ActorRefAdapteris not allocated unlessselfis actually accessedActorAdapter.scala—val supervisorStrategy→final override def supervisorStrategyto avoid per-instance field allocationTest coverage (
PropsAdapterSpec.scala)Added tests covering all
PropsAdaptercode 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")