-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Avoid marking types as reflected on in CreateSpan #118832
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
Conversation
This seems to be at least one of the reasons why Hello World on Linux still needs support for boxed enums. `CreateSpan` is used with an enum type in Unix System.Console, which brings a boxed enum into whole program view and we can't undo the damage this causes to the whole program view during compilation anymore (even though we no longer need the `typeof` then because RyuJIT always expands `CreateSpan`).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes NativeAOT compilation by avoiding unnecessary type reflection marking in the CreateSpan<T> method. The change prevents enum types from being marked as reflected-on when CreateSpan is called, which was causing unnecessary bloat in Hello World applications on Linux that required support for boxed enums.
Key Changes:
- Moves the
PlatformNotSupportedExceptionthrow earlier in the call chain for NativeAOT to avoid executingtypeof(T).TypeHandle - Removes the unused
GetSpanDataFromhelper method from the NativeAOT-specific implementation - Adds conditional compilation to handle the method differently between NativeAOT and other runtimes
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| RuntimeHelpers.cs | Adds NativeAOT-specific conditional compilation to throw exception before type reflection occurs |
| RuntimeHelpers.NativeAot.cs | Removes unused GetSpanDataFrom helper method that was only throwing exceptions |
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs
Outdated
Show resolved
Hide resolved
|
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
…erServices/RuntimeHelpers.cs
|
/ba-g infrastructure timeout (Mono_MiniJIT_LibrariesTests running for 8 hours) |
|
/backport to release/10.0 |
|
Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/17083153276 |
This seems to be the only reason why Hello World on Linux still needs support for boxed enums.
CreateSpanis used with an enum type in Unix System.Console, which brings a boxed enum into whole program view and we can't undo the damage this causes to the whole program view during compilation anymore (even though we no longer need thetypeofthen because RyuJIT always expandsCreateSpan).