React Compiler: Store aliasing values in an inline set - #37366
Open
andrewimm wants to merge 2 commits into
Open
Conversation
97.6% of the value sets tracked per identifier in mutation / aliasing inference hold exactly one element, but each was a `FxHashSet`, meaning each was a heap allocation. Because the inference code retains a full state in each basic block, these single-element hashsets were a major contributor to peak memory allocation. This replaces them with a small inline set inspired by smolvec / tinyvec. Five values are stored inline, and any more spill to the heap. This was only needed in **0.02%** of sets in my data corpus. This also makes iteration order match the TS implementation. TS uses `Set` and iterates in insertion order; the Fx set iterated in hash order. This brings the two behaviors in line. | Benchmark | Peak allocation | Allocation count | Wall time | |------------------|----------------------------|------------------|-----------| | legacy/image.tsx | 58.47 -> 53.25 MiB (-8.9%) | -31.6% | -21.1% | | next-client | 58.47 -> 53.11 (-9.2%) | -25.0% | -14.0% | | devtools | 26.58 -> 24.52 (-7.8%) | -15.6% | -8.6% | | fixtures | 17.47 -> 15.95 (-8.7%) | -7.8% | -3.1% | | next-examples | 6.22 -> 5.98 (-3.9%) | -5.2% | -1.1% |
Building on the `ValueIdSet`, let's store the spilled values in a boxed slice instead of a Vec. A Vec has 32 bytes, a Boxed slice only has 24. This is another 7-9% memory savings on top of the previous commit.
Collaborator
Author
|
Building on the |
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.
97.6% of the value sets tracked per identifier in mutation / aliasing inference hold exactly one element, but each was a
FxHashSet, meaning each was a heap allocation.Because the inference code retains a full state in each basic block, these single-element hashsets were a major contributor to peak memory allocation.
This replaces them with a small inline set inspired by smolvec / tinyvec. Five values are stored inline, and any more spill to the heap. This was only needed in 0.02% of sets in my data corpus.
This also makes iteration order match the TS implementation. TS uses
Setand iterates in insertion order; the Fx set iterated in hash order. This brings the two behaviors in line.