Skip to content

Deduplicate identical ReadyToRun Wasm method bodies #134598

Closed

Description

@davidwrighton

Problem

ReadyToRun Wasm images contain many methods with exactly identical emitted function bodies. Emitting each copy independently increases download size and leaves no shared compiler representation that could later support broader folding.

A recent retail System.Private.CoreLib.wasm measurement found 1,879 signature-compatible exact-body groups containing 7,568 redundant bodies, representing roughly 342 KB of Code-section bytes before accounting for method-identity constraints.

Proposed change

Add exact method-body deduplication at the ReadyToRun dependency-analysis layer rather than in the Wasm object writer.

The initial implementation should fold only methods whose emitted body, relocations, signature requirements, and runtime identity requirements are exactly compatible. The abstraction should permit future extension to methods with equivalent GC information; placing the decision in the object writer would make that substantially harder.

The design must preserve required R2R method-index, entrypoint, stack-walking, EH, and MethodDesc behavior.

Validation

  • Add focused dependency-analysis tests where practical.
  • Build CoreCLR browser/Wasm in Release.
  • Verify folded methods share the intended implementation without losing required method metadata.
  • Compare function counts, Code-section size, startup, and focused execution.

Note

This issue was generated with GitHub Copilot.

Activity

  1. dotnet-policy-service commented on Sep 24, 2026

    @dotnet-policy-service
    Contributor

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

  2. added a commit that references this issue on Oct 9, 2026
    91c573e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions