fix: match actor selection wildcards without backtracking (#3506) - #3519
Merged
Conversation
* fix: match actor selection wildcards without backtracking Motivation: SelectChildPattern compiled its glob to a regular expression with Helpers.makePattern, which turns every '*' into '.*'. A chain of those backtracks: the 26 character pattern "*a*a*a*a*a*a*a*a*a*a*a*a*b" matched against a 36 character actor name that cannot satisfy the trailing literal takes about 42 seconds on one thread. An ActorSelectionMessage carries its pattern elements in the message, so that cost is reachable from one small message, and deliverSelection runs on the caller's thread for a local selection and on the inbound stream thread for a remote one. Bounding the pattern length would not help, since 26 characters is already enough. Modification: Add Glob (@internalapi), which matches the same grammar - '?' is one character, '*' is any run, everything else is literal - by remembering only the most recent '*' rather than by backtracking, so it runs in time proportional to the product of the two lengths at worst. Match through it in ActorSelection.deliverSelection. SelectChildPattern.pattern is kept for compatibility but is now lazy, so deserializing a selection no longer compiles a regular expression either. Result: The same selections match as before, in time linear in practice. * scalafmt
pjfanning
requested review from
He-Pin,
Philippus,
nvollmar,
raboof and
samueleresca
September 4, 2026 09:45
nvollmar
approved these changes
Sep 4, 2026
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
Backport of #3506 to 1.7.x: wildcard actor-selection matching went through a regular
expression that backtracks badly — a 26-character pattern in an
ActorSelectionMessagecould pin the inbound stream thread for tens of seconds.
Modification
Cherry-pick of ec62931. The only conflict was the import line in
ActorSelection.scala(1.7.x also imports
JavaDurationConverters,ccompatandFutureConvertersthere);resolved by adding
Globto the existing import.Glob.scalaandGlobSpecappliedclean — they are plain Scala 2 syntax and Java 8 APIs throughout.
Result
Same as #3506: the same selections match as before, in time linear in practice, and
deserializing a selection no longer compiles a regular expression.
Tests
sbt "++ 2.12.21 actor-tests/Test/compile"— clean, validating Scala 2.12sbt "actor/scalafmtCheckAll" "actor-tests/scalafmtCheckAll"— cleanfrom fix: match actor selection wildcards without backtracking #3506, including the exhaustive agreement check against
Helpers.makePatternReferences
Backport of #3506.