Repository navigation
fix: index ancestor caches by native tag with Map/Set - #2
Merged
Merged
Conversation
jpudysz
marked this pull request as ready for review
October 21, 2026 09:28
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.
Problem
collectVisibleAncestorsandcollectAncestorskept their per-call caches in plain arrays indexed bystateNode.canonical.nativeTag. Native tags only grow: every view ever mounted takes a new one. Each call writes hundreds of scattered, large tag indexes into a fresh array. As tags grow, Hermes allocates far more for those writes than for a Map/Set, so the cost grows with session length.Both consumers call these after every theme change:
collectVisibleAncestorsin the ShadowRegistry refresh.collectAncestorsinrefreshReactNodes.The garbage shows up as extra GCs on unrelated work, like re-renders.
One
collectAncestorscall over 900 hostsPer flip
Before, flip allocation grows every round:
After, it stays flat at 1.68 MB / 3.35 MB.
Wall-clock
Mount (~25 ms), re-render (~19 ms) and unmount (~4 ms) show no difference beyond noise. A flip window (40-90 ms,
setThemeto the next idle callback) is dominated by native work and idle scheduling, so it can't resolve a sub-millisecond JS change. With fresh tags the Map/Set version costs about +0.02 ms per call.Earlier measurement in Unistyles (900 views, 28 rounds per launch, A/B against v3.5.3): total allocation went from 2181 MB to 1952 MB with this change, and GC time dropped about 8.5% below v3.5.3.