-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use PackedIndexOfIsSupported checks in more places #80254
Use PackedIndexOfIsSupported checks in more places #80254
Conversation
This should avoids the size regression on WebAssembly and possibly other platforms without Sse2. The regression is side effect of dotnet#78861 which uses `PackedSpanHelpers.CanUsePackedIndexOf (!!T)` and TShouldUsePacked.Value to guard the usage of PackedSpanHelpers. Because these involve generics, illinker is unable to link the PackedSpanHelpers type away and that pulls other parts in, like System.Runtime.Intrinsics.X86.* types. See https://gist.github.com/radekdoulik/c0b52247d472f69bcf983ade78a924ea for more complete list. This change gets us back 9,216 bytes in the case of app used to repro the regression. ... - Type System.PackedSpanHelpers - Type System.Runtime.Intrinsics.X86.X86Base - Type System.Runtime.Intrinsics.X86.Sse - Type System.Runtime.Intrinsics.X86.Sse2 Summary: - 9,216 File size -0.76% (of 1,215,488) - 2,744 Metadata size -0.43% (of 636,264) - 4 Types count
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
@vitek-karas @sbomer, do you think the linker might be able to evaluate the checks involving generics in future? |
src/libraries/System.Private.CoreLib/src/System/IndexOfAnyValues/IndexOfAnyValues.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IndexOfAnyValues/IndexOfAnyValues.cs
Outdated
Show resolved
Hide resolved
It would be nice if at least cases like runtime/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.Packed.cs Lines 26 to 31 in 7f93bd6
could be handled given that PackedIndexOfIsSupported is the first condition we check.
|
I'll look into it a bit - I don't the generics are the problem. I think the problem is that our analysis is not smart enough to figure out that if the |
…es/IndexOfAnyValues.cs Co-authored-by: Miha Zupan <[email protected]>
…es/IndexOfAnyValues.cs Co-authored-by: Miha Zupan <[email protected]>
This is what the linker produces for CanUsePackedIndexOf:
|
@radekdoulik looking at your diff of methods and types, it looks like the linker was already able to strip out the There are two usage patterns here:
|
That might be possible, I first added the checks to |
This is very difficult to implement - it requires analyzing the entire app to figure out that TrueConst is not needed, remove it and then go back and "fixup" all callsites which can now assume a const Also of note - these kind of optimizations are currently treated as that - just optimizations, so the tools are free to "give up" on them if it's too difficult. It also means that different tools will have different behaviors. For example, I would not be surprised if NativeAOT didn't work the same way in this particular case. @sbomer is probably going to look into defining the minimum bar for feature switch based trimming which would then become a guaranteed functionality in the tools, but we don't have that yet. Also - expect the min bar to be pretty minimum. |
I have tried version with removed changes in |
The timeout is probably #79255 |
This should avoid the size regression on WebAssembly and possibly other platforms without Sse2.
The regression is side effect of #78861 which uses
PackedSpanHelpers.CanUsePackedIndexOf (!!T)
and TShouldUsePacked.Value to guard the usage of PackedSpanHelpers.Because these involve generics, illinker is unable to link the PackedSpanHelpers type away and that pulls other parts in, like System.Runtime.Intrinsics.X86.* types. See https://gist.github.com/radekdoulik/c0b52247d472f69bcf983ade78a924ea for more complete list.
This change gets us back 9,216 bytes in the case of app used to repro the regression.