[MicroPerf] Avoid redundant FreeVars record allocation for local vals - #20354
Open
T-Gro wants to merge 2 commits into
Open
[MicroPerf] Avoid redundant FreeVars record allocation for local vals#20354T-Gro wants to merge 2 commits into
T-Gro wants to merge 2 commits into
Conversation
Contributor
|
T-Gro
marked this pull request as draft
August 26, 2026 08:01
accFreeLocalVal and boundLocalVal accumulated the free type variables of the val's type and then separately added/removed the val from FreeLocals, allocating two FreeVars records whenever the type contributed a free type variable. Fold both into a single record update, factoring the shared type-variable accumulation into `accFreeTyvarsInVal` (used by both) and dropping the now-unused accFreevarsInVal helper. Output is byte-for-byte identical: accFreeInVal only accumulates into FreeTyvars, never FreeLocals, so computing the type contribution before the FreeLocals membership check is order-independent. Measured on a 65,880-LOC / 120-file compile (net11.0, Release): 177,250 redundant FreeVars records eliminated per compile (~11 MB); FreeVars record allocation down 5.4% in a gc-verbose trace. Byte identity confirmed by comparing per-file deterministic (--deterministic+) output hashes across all 120 files (manifest hash unchanged vs HEAD). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
T-Gro
force-pushed
the
t-gro-freevar-perf-spike
branch
from
August 26, 2026 08:20
a07eac8 to
96d41b1
Compare
T-Gro
marked this pull request as ready for review
August 26, 2026 09:12
T-Gro
enabled auto-merge (squash)
August 26, 2026 09:12
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.
Folds the two
FreeVarsallocations inaccFreeLocalVal/boundLocalVal— free-type-variable accumulation and theFreeLocalsupdate — into one record. Safe because the type walk (accFreeInVal) writes onlyFreeTyvars, neverFreeLocals, so the updates are independent.Self-compile of
src/Compiler, 65,880 LOC / 120 files, net11.0 Release,--optimize+:FreeVarsallocation, 1 compileCompiler-output identity: assemblies emitted by the patched compiler are byte-for-byte identical to those from unmodified
main— each of the 120 files compiled--deterministic+to a fixed output path, SHA-256 equal on both. Corroborated by an in-process check comparing the old and newFreeVarsat every call across one compile: 3,727,347 calls, 0 differences.