Skip to content
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

Make typeof(T).GUID an intrinsic on NAOT where possible (like .NET Native) #95184

Closed
Sergio0694 opened this issue Nov 23, 2023 · 2 comments · Fixed by #95212
Closed

Make typeof(T).GUID an intrinsic on NAOT where possible (like .NET Native) #95184

Sergio0694 opened this issue Nov 23, 2023 · 2 comments · Fixed by #95212
Labels
area-NativeAOT-coreclr trimming-for-aot `EnableAggressiveTrimming=true` used for running tests with AOT

Comments

@Sergio0694
Copy link
Contributor

Sergio0694 commented Nov 23, 2023

Description

Especially in interop scenarios, it's rather common to use typeof(T).GUID to get the Guid associated with a given type. This currently causes a whole lot of reflection cruft to be preserved, which just on its own can exceed 300 KB of stuff, purely rooted by typeof(T).GUID. I was wondering whether it would be possible to make this an intrinsic, at least for NativeAOT. In theory, shouldn't the compiler always have all the necessary information to compute the GUID ahead of time? Or at least, could it not do that in all cases where the type T has the [Guid] attribute applied to it? IIRC, .NET Native has a similar optimization, where it can just bake all of these typeof(T).GUID uses directly into the codegen, making this pretty much free.

Could we do the same on NativeAOT?

Configuration

.NET 8.0.100

Regression?

No, always been this way.

Data

This is a screenshot from @MichalStrehovsky's sizoscope tool, from a ComputeSharp sample, after removing typeof(T).GUID:

image

This is from Sergio0694/ComputeSharp#669. Just this saved a total of 304 KB in my sample.

Here's some precompiled diffs with MSTAT info, for baseline and with that PR applied to it: native-guid_diffs.zip.

Note

Related to #91518.

@Sergio0694 Sergio0694 added trimming-for-aot `EnableAggressiveTrimming=true` used for running tests with AOT area-NativeAOT-coreclr labels Nov 23, 2023
@ghost
Copy link

ghost commented Nov 23, 2023

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

Issue Details

Description

Especially in interop scenarios, it's rather common to use typeof(T).GUID to get the Guid associated with a given type. This currently causes a whole lot of reflection cruft to be preserved, which just on its own can exceed 300 KB of stuff, purely rooted by typeof(T).GUID. I was wondering whether it would be possible to make this an intrinsic, at least for NativeAOT. In theory, shouldn't the compiler always have all the necessary information to compute the GUID ahead of time? Or at least, could it not do that in all cases where the type T has the [Guid] attribute applied to it? IIRC, .NET Native has a similar optimization, where it can just bake all of these typeof(T).GUID uses directly into the codegen, making this pretty much free. Could we do the same on NativeAOT?

Configuration

.NET 8.0.100

Regression?

No, always been this way.

Data

This is a screenshot from @MichalStrehovsky's sizoscope tool, from a ComputeSharp sample, after removing typeof(T).GUID:

image

This is from Sergio0694/ComputeSharp#669. Just this saved a total of 304 KB in my sample.

Here's some precompiled diffs with MSTAT info, for baseline and with that PR applied to it: native-guid_diffs.zip.

Author: Sergio0694
Assignees: -
Labels:

trimming-for-aot, area-NativeAOT-coreclr

Milestone: -

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 23, 2023
jkotas added a commit to jkotas/runtime that referenced this issue Nov 24, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Nov 24, 2023
@jkotas
Copy link
Member

jkotas commented Nov 24, 2023

This currently causes a whole lot of reflection cruft to be preserved, which just on its own can exceed 300 KB of stuff

This cruft was pulled in by universal custom attribute reader that handles all types that can show up in custom attributes. Most of it was the type loader that is not really reflection. #95212 removes this dependency by using a reader that just handles strings (the only case required for GuidAttribute).

Make typeof(T).GUID an intrinsic

I do not think it makes sense to complicate JIT with this.

jkotas added a commit that referenced this issue Nov 25, 2023
@ghost ghost removed in-pr There is an active PR which will close this issue when it is merged untriaged New issue has not been triaged by the area owner labels Nov 25, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-NativeAOT-coreclr trimming-for-aot `EnableAggressiveTrimming=true` used for running tests with AOT
Projects
None yet
3 participants
@jkotas @Sergio0694 and others