Skip to content

[MicroPerf] Reduce Detuple usage-analysis allocation with a mutable Dictionary - #20351

Merged
T-Gro merged 2 commits into
dotnet:mainfrom
T-Gro:t-gro-maptree-alloc-spike
Aug 28, 2026
Merged

[MicroPerf] Reduce Detuple usage-analysis allocation with a mutable Dictionary#20351
T-Gro merged 2 commits into
dotnet:mainfrom
T-Gro:t-gro-maptree-alloc-spike

Conversation

@T-Gro

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

Copy link
Copy Markdown
Member

Detuple GlobalUsageAnalysis.Uses: Zmap<Val,_> → per-file mutable Dictionary. logUse re-adds the same key on every occurrence; each add path-copied the whole AVL tree before.

65k-LOC compile, net11.0 Release:

  • MapTreeNode<Val, _ list> (this map): 634 MB → 0
  • total allocated / compile: 10,668 MB → 10,477 MB (−191 MB, ~1.8%)

@T-Gro
T-Gro requested a review from a team as a code owner August 25, 2026 15:33
@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

@github-actions github-actions Bot added the AI-Tooling-Check-Scanned-Clean Tooling check: diff analyzed, no interesting infrastructure files label Aug 25, 2026
@T-Gro
T-Gro marked this pull request as draft August 26, 2026 08:02
@T-Gro
T-Gro force-pushed the t-gro-maptree-alloc-spike branch 2 times, most recently from 9552876 to 605b9b2 Compare August 26, 2026 08:38
Detuple.GlobalUsageAnalysis threads a Uses map (Zmap<Val,_>) through a
per-file fold; logUse does tryFind+add on every value occurrence, so a value
used K times re-inserts at the same key K times, each path-copying the whole
balanced tree. This is the largest MapTree.mk allocation source in the
optimizer. A per-file mutable Dictionary (BagAdd) removes the churn; Uses is
only grown during the sequential per-file fold and read back by point lookup
or one enumeration sorted by (valSourceOrderKey, Stamp), so its iteration
order never reaches output.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 69e8646f-b2d9-4852-af5c-5f96dc2d36a3
@T-Gro
T-Gro force-pushed the t-gro-maptree-alloc-spike branch from 605b9b2 to ce9ed28 Compare August 26, 2026 09:07
@T-Gro
T-Gro marked this pull request as ready for review August 26, 2026 09:13
@T-Gro
T-Gro requested a review from abonie August 26, 2026 09:13
@T-Gro T-Gro changed the title Reduce Detuple usage-analysis allocation with a mutable Dictionary [MicroPerf] Reduce Detuple usage-analysis allocation with a mutable Dictionary Aug 27, 2026
@T-Gro
T-Gro enabled auto-merge (squash) August 27, 2026 08:20
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 AI-Tooling-Check-Scanned-Clean Tooling check: diff analyzed, no interesting infrastructure files 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