-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
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:
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.
