Skip to content

[MicroPerf] Reverse instead of sort already-ordered branch fixups in IL writer - #20349

Merged
T-Gro merged 3 commits into
mainfrom
t-gro-perf-applybrfixups-sort
Sep 9, 2026
Merged

[MicroPerf] Reverse instead of sort already-ordered branch fixups in IL writer#20349
T-Gro merged 3 commits into
mainfrom
t-gro-perf-applybrfixups-sort

Conversation

@T-Gro

@T-Gro T-Gro commented Aug 25, 2026

Copy link
Copy Markdown
Member

Output-identical: emitted IL and metadata are byte-for-byte unchanged on every workload checked.

applyBrFixups stable-sorted the required branch fixups by code offset once per emitted method body. Fixups are recorded by prepending at the current code position as the stream is emitted linearly, so the list always arrives strictly descending by offset with no ties — the sort is exactly a reverse. Replaced List.sortBy with List.rev.

Measured over a 65,880-LOC / 120-file compile (net11 Release; ~46,465 calls/compile, 88% empty lists, longest 25): 0.595 ms → 0.240 ms and 1444 KB → 634 KB allocated per compile for this step. Isolated microbench on the same call-length distribution is ~3× faster at ~2.3× less allocation, and beats a packed-int64 Array.Sort and every other candidate tried.

Equivalence was checked by computing both orderings for every emitted method during a full compile and comparing element-for-element: 139,370 method bodies, 0 mismatches (and every list confirmed strictly descending, 0 ties).

@T-Gro
T-Gro requested a review from a team as a code owner August 25, 2026 14:58
@T-Gro T-Gro added NO_RELEASE_NOTES Label for pull requests which signals, that user opted-out of providing release notes AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed labels Aug 25, 2026
@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

⚠️ Release notes required, but author opted out

Warning

Author opted out of release notes, check is disabled for this pull request.
cc @dotnet/fsharp-team-msft

@T-Gro
T-Gro marked this pull request as draft August 26, 2026 08:03
origReqdBrFixups is recorded by prepending at strictly-increasing code
positions, so it always arrives strictly descending by fixupLoc with no
ties. The stable List.sortBy is therefore exactly List.rev. Output is
byte-for-byte identical.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@T-Gro
T-Gro force-pushed the t-gro-perf-applybrfixups-sort branch from e87474e to b0770fe Compare August 26, 2026 08:10
@T-Gro
T-Gro marked this pull request as ready for review August 26, 2026 08:24
@T-Gro
T-Gro requested a review from abonie August 26, 2026 08:25
@T-Gro
T-Gro marked this pull request as draft August 26, 2026 08:44
@T-Gro
T-Gro marked this pull request as ready for review August 26, 2026 08:44
@T-Gro
T-Gro enabled auto-merge (squash) August 26, 2026 08:44
@T-Gro T-Gro changed the title Reverse instead of sort already-ordered branch fixups in IL writer [MicroPerf] Reverse instead of sort already-ordered branch fixups in IL writer Aug 27, 2026
Comment thread src/Compiler/AbstractIL/ilwrite.fs
@github-project-automation github-project-automation Bot moved this from New to In Progress in F# Compiler and Tooling Aug 28, 2026
Copilot and others added 2 commits September 2, 2026 15:53
…dBrFixups

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@T-Gro
T-Gro disabled auto-merge September 9, 2026 12:47
@T-Gro
T-Gro merged commit a2806ef into main Sep 9, 2026
52 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in F# Compiler and Tooling Sep 9, 2026
@T-Gro
T-Gro deleted the t-gro-perf-applybrfixups-sort branch September 9, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed NO_RELEASE_NOTES Label for pull requests which signals, that user opted-out of providing release notes Theme-Performance

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants