[MicroPerf] Inline the free-variable typar foldBacks - #9
Closed
T-Gro wants to merge 1 commit into
Closed
Conversation
accFreeInTyparConstraints and accFreeInTypars fold accFreeInTyparConstraint / accFreeTyparRef over a typar's constraint and typar lists during free-variable computation, one of the hottest traversals in the compiler. Passing those top-level functions to List.foldBack allocated a partial- application closure per call, over typically tiny (often empty) lists where the closure is the entire cost. Switch both folds to ListInline.foldBack (added in the parent change), whose InlineIfLambda folder inlines the top-level partial application, so no closure is allocated. Fold order is unchanged; compiler output is byte-identical under --deterministic+. Measured (dotnet-trace gc-verbose, 6 self-compiles of a 120-file corpus): accFreeInTyparConstraints closure 147.8 MB -> 0, accFreeTyparRef closure 238.8 MB -> 0. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c6610fae-a96e-4421-a920-e73de4fc94dc
T-Gro
marked this pull request as draft
August 27, 2026 12:52
Owner
Author
|
Superseded by dotnet#20385 (proper same-repo stacked PR). |
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.
Stacked on dotnet#20373 — depends on its
ListInlinemodule. Base is this PR's branch on the fork (a dotnet/fsharp PR can't use a fork branch as base); it retargets tomainonce dotnet#20373 merges.Free-variable computation is one of the hottest compiler traversals.
accFreeInTyparConstraintsandaccFreeInTyparsfold the top-levelaccFreeInTyparConstraint/accFreeTyparRefover a typar's constraint and typar lists — usually tiny or empty. Passed toList.foldBack, each call allocated a partial-application closure; sincefoldBackbuilds no result list, that closure is the entire allocation.ListInline.foldBackinlines the folder (InlineIfLambda) and the top-level partial application fuses, so nothing is allocated.Closures eliminated (dotnet-trace
gc-verbose, 6 self-compiles of a 120-file corpus):accFreeInTyparConstraint opts(foldBack)accFreeTyparRef opts(foldBack)Fold order is unchanged, so free-variable results are identical; compiler output is byte-identical under
--deterministic+(SHA-256 match vs base), and tests pass.