Cherry-pick FCollection from #11366 - #11431
Merged
Merged
Conversation
FCollection kept a HashSet beside its list purely to reject duplicate adds and answer contains() in O(1). Trait rebuilds (getReplacementEffects / getStaticAbilities / getTriggers, plus every FCollection copy they make) create tens of millions of these per game, almost all holding one or two elements and never queried by value - so the set was pure overhead: an extra allocation per collection and a hash insert per element. Build the set on demand instead. Until something needs value semantics at scale (asSet, or growth past a small threshold) uniqueness is enforced by scanning the list, which is cheaper than the set for the tiny sizes that dominate. Also copy straight across the backing list when constructing from another FCollection (the source already guarantees uniqueness) and skip iterating empty collections in addAll. Verified against a fixed 5-seed AI-vs-AI match on a 510-card deck: every game's end state is byte-identical to before, and total match time drops substantially (the set churn was the single largest allocation source in the profile). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Hanmac
approved these changes
Jul 27, 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.
@Hanmac
I looked into just using
LinkedHashSetbut it's missing too many methods imo.