You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[wasm] Managed Wide-Vector (256, 512) SIMD Fallbacks are Very Expensive in Size #136741
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
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.
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?
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.
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.
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.
Activity
dotnet-policy-service commentedon Oct 30, 2026
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Oct 30, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
adamperlin commentedon Oct 30, 2026
cc also @tannergooding
tannergooding commentedon Oct 30, 2026
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.
AndyAyersMS commentedon Nov 12, 2026
@adamperlin @davidwrighton can we work up changes that omit methods with these typs from Wasm R2R?
adamperlin commentedon Nov 13, 2026
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?jkotas commentedon Nov 16, 2026
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.
davidwrighton commentedon Nov 16, 2026
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.
JulieLeeMSFT commentedon Nov 25, 2026
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.