-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Optimize out metadata for typeof(X).IsValueType
and .IsEnum
#118528
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
base: main
Are you sure you want to change the base?
Conversation
We don't need reflection metadata to answer this. Change salvaged out of dotnet#118479, rt-sz will decide if we want it.
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 the AOT compilation process by avoiding the generation of unnecessary reflection metadata for simple type queries. The optimization specifically targets patterns like typeof(X).IsValueType
and typeof(X).IsEnum
where the answer can be determined at compile time without requiring full reflection metadata.
Key changes:
- Adds pattern detection for
typeof(X).IsValueType
andtypeof(X).IsEnum
call sequences - Modifies helper ID assignment to use
NecessaryTypeHandle
instead of full metadata when these patterns are detected
src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs
Outdated
Show resolved
Hide resolved
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
The savings are borderline, but maybe worth it given the low complexity: Size statisticsPull request #118528
|
…r.cs Co-authored-by: Copilot <[email protected]>
/azp run runtime-nativeaot-outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
{ | ||
if (reader.HasNext | ||
&& reader.ReadILOpcode() is ILOpcode.callvirt or ILOpcode.call | ||
&& _methodIL.GetObject(reader.ReadILToken()) is MethodDesc { Name: "get_IsValueType" or "get_IsEnum"}) |
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.
Add IsPrimitive too? It is used in some places in BCL.
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.
Let's see what rt-sz says. We can do this for several other properties but I wasn't sure how much of a coupling between the compiler and the BCL we are okay with in this area.
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.
If we wanted to avoid coupling between the compiler and the BCL, we would make this pattern must-expand in the JIT. It would reduce the coupling to JIT/scanner that exists in many places.
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.
Do we have a test coverage for the (rare) situation when the JIT does not expand this pattern as an intrinsic?
/azp run runtime-nativeaot-outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
We don't need reflection metadata to answer this.
Change salvaged out of #118479, rt-sz will decide if we want it.