Skip to content

[wasm] Managed Wide-Vector (256, 512) SIMD Fallbacks are Very Expensive in Size #136741

Open

Description

@adamperlin

This is a broader issue that came up while investigating Wasm size outliers in System.Private.CoreLib as compared to x64 R2R codegen. Nearly all the statistical size outliers were in vector fallback code. For example, the fallback code for Vector512.FusedMultiplyAdd<float> is massive on Wasm; it's around 1.8 KB in size, as compared to only 47 bytes on x64. The comparison isn't fair necessarily because x64 has vector intrinsics that Wasm simply does not have, but this example exposes several things we might want to look into:

  • We don't seem to decompose larger vector widths into v128 locals; i.e., accessing elements of a Vector512 struct will end up as many separate loads and stores of v128. This could be complicated to improve but it is definitely a factor in the large code size and likely has significant negative perf impacts as well.
  • We null check addresses for loads of individual vector elements in stack allocated vectors which should be in bounds for the current stack frame;
  • We aggressively inline nested managed fallbacks which leads to a very large code size expansion. In this example we have the inline tree of Vector512.FusedMultiplyAdd -> 2*Vector256.FusedMultiplyAdd -> 2*Vector128.FusedMultiplyAdd -> 2*Vector64.FusedMultiplyAdd -> 2*Vector64.GetElementUnsafe

Activity

  1. added
    untriaged
    on Oct 30, 2026
  2. added
    arch-wasm
    tenet-performance
    area-CodeGen-coreclr
    on Oct 30, 2026
  3. dotnet-policy-service commented on Oct 30, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
    See info in area-owners.md if you want to be subscribed.

  4. dotnet-policy-service commented on Oct 30, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  5. removed
    untriaged
    on Oct 30, 2026
  6. adamperlin commented on Oct 30, 2026

    @adamperlin
    ContributorAuthor
  7. tannergooding commented on Oct 30, 2026

    @tannergooding
    Member

    These types should really only be accessed when VectorXXX.IsHardwareAccelerated == true, it is reasonable to not include them in the R2R set and to instead leave them to interpreter only. Anyone explicitly using them otherwise (including any accidental code we have) is not following best practices and should adjust their handling.

    Of course there's nothing wrong with improving codegen here too, just it seems like an easy thing to cut.

  8. AndyAyersMS commented on Nov 12, 2026

    @AndyAyersMS
    Member

    @adamperlin @davidwrighton can we work up changes that omit methods with these typs from Wasm R2R?

  9. adamperlin commented on Nov 13, 2026

    @adamperlin
    ContributorAuthor

    @adamperlin @davidwrighton can we work up changes that omit methods with these types from Wasm R2R?

    I imagine there is though I'm not sure exactly how? @davidwrighton is there a way to omit namespaces in R2R, like for example we could omit System.Runtime.Intrinsics.Vector512?

  10. jkotas commented on Nov 16, 2026

    @jkotas
    Member

    Our primary focus should be size of trimmed release apps. We should get IL and metadata trimmed for these intrinsics in typical wasm apps - it will address the wasm code size bloat as well.

  11. davidwrighton commented on Nov 16, 2026

    @davidwrighton
    Member

    Yeah, I don't want to change anything in crossgen2 for this unless we can show that the trimmer isn't able to deal with the problem itself. Lets see what typical apps do. This is why when I'm making targetted changes that I'm looking at the Havit scenario instead of just System.Private.CoreLib. It is unfortunate though, since the Havit scenario isn't quite as easy to trigger as System.Private.CoreLib.

  12. JulieLeeMSFT commented on Nov 25, 2026

    @JulieLeeMSFT
    Member

    Per the discussion, if Havit and other representative release apps trim away the fallbacks, we will close this issue as not planned for app size. If the fallbacks survive and meaningfully increase download size, we will investigate why.

  13. added this to the 12.0.0 milestone on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasmarea-CodeGen-coreclrtenet-performance

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions