Skip to content

Deduplicator; add case when both methods fold into a third - #137572

Merged
MichalStrehovsky merged 1 commit into
dotnet:mainfrom
manofstick:method-body-deduplicator-handle-additional-case
Nov 16, 2026
Merged

MichalStrehovsky merged 1 commit into
dotnet:mainfrom
manofstick:method-body-deduplicator-handle-additional-case

Conversation

@manofstick

Copy link
Copy Markdown
Contributor

Working on AOT compilation of Cistern.ValueLinq I noticed that the folding of methods wasn't handling the case when both folded into a 3rd (i.e. the did A=B or A=C, but not B=C).

This minor change handles that case. For Cistern, a compilation of the corefx-linq based test suite (that Cistern carries a copy of), this results in a 5% reduction in the compiled size. There are much more modest, but not completely insignificant changes.

As an example crossgen2 was compiled (linux-x64, Release) with ilc built from baseline and from this change. Section sizes in bytes of the resulting object file.

--methodbodyfolding:generic (crossgen2's default):

baseline with change
__managedcode 6,180,402 6,156,706 (−24 KB, −0.4%)
.eh_frame 1,097,156 1,092,400
.rodata 4,155,794 4,151,426
text symbols (nm) 31,005 30,920 (−85)

--methodbodyfolding:all:

baseline with change
__managedcode 6,060,066 6,024,082 (−36 KB, −0.6%)
.eh_frame 1,009,196 1,002,312
.rodata 4,062,882 4,056,130
text symbols (nm) 28,126 28,001 (−125)

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 15, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/crossgen-contrib
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change to compare relocation targets by their interned representatives.

No open issues 🎉

What changed in this PR

This PR improves NativeAOT method-body deduplication by recognizing equivalent relocation targets when both have folded into a shared third method, enabling additional code-size reductions.

Changes:

  • Compare relocation targets by their interned representatives, preserving direct-fold comparisons while covering shared representatives.
  • Update comments to describe the expanded equality behavior and its consistency with hashing.
File Description
src/​coreclr/​tools/​aot/​ILCompiler.Compiler/​Compiler/​MethodBodyDeduplicator.cs Adds representative-based target comparison and clarifies deduplication comments.

Review effort: Balanced

@MichalStrehovsky MichalStrehovsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like up to 0.6% savings with StackTraceSupport=false. Nice, thanks!

@MichalStrehovsky

Copy link
Copy Markdown
Member

/ba-g osx timeouts

@MichalStrehovsky
MichalStrehovsky merged commit a33eebb into dotnet:main Nov 16, 2026
108 of 111 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ReadyToRun community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants