-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
💾 Bringing the size of Native AOT Hello World under 1.44 MB #83069
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue Details...because someone might want to put a Hello World (compiled with the default compiler settings) on a floppy. Of course we can go smaller if one starts disabling features like globalization or stack traces. But the defaults are interesting. The theme is: type loader should not be necessary in a Hello World and we should be able to trim it.
With the above (and hacks for the last two), I see default Hello World at 1.46 MB, down from 1.77 MB.
|
Attribute.Equals/GetHashCode is currently implemented using reflection. The implementation iterates over all instance fields and calls Equals/GetHashCode as needed. This has problems because the code is not actually trim safe (requires special casing in the compiler to work around an invalid suppression in CoreLib) and has extra problems for reflection blocking (we need to make sure the fields are never subject to blocking). In this PR I'm switching Attribute to a similar plan that .NET Native had. In .NET Native we injected a pair of virtual methods to read and access fields on System.Attribute descendants. We can actually get away with one method - I'm reusing all the infrastructure we have for ValueType.Equals/GetHashCode since the problem is the same. Saves 5.8% on a Hello World. For BasicMinimalApi, this is a wash (almost to the byte). It will become an improvement once RyuJIT starts generating better code for the field offset computations we're doing in the injected method. Contributes to dotnet#83069.
Attribute.Equals/GetHashCode is currently implemented using reflection. The implementation iterates over all instance fields and calls Equals/GetHashCode as needed. This has problems because the code is not actually trim safe (requires special casing in the compiler to work around an invalid suppression in CoreLib) and has extra problems for reflection blocking (we need to make sure the fields are never subject to blocking). In this PR I'm switching Attribute to a similar plan that .NET Native had. In .NET Native we injected a pair of virtual methods to read and access fields on System.Attribute descendants. We can actually get away with one method - I'm reusing all the infrastructure we have for ValueType.Equals/GetHashCode since the problem is the same. Saves 5.8% on a Hello World. For BasicMinimalApi, this is a wash (almost to the byte). It will become an improvement once RyuJIT starts generating better code for the field offset computations we're doing in the injected method. Contributes to #83069.
Resolves dotnet#83069. Hello World is now 1.45 MB, down from 1.65 MB. Half of the callers don't care about the `MethodNameAndSignature` part - don't spend time computing it. This also allows trimming `MethodNameAndSignature` from a hello world, which allows trimming pretty much all of the type loader.
Resolves #83069. Hello World is now 1.45 MB, down from 1.65 MB. Half of the callers don't care about the `MethodNameAndSignature` part - don't spend time computing it. This also allows trimming `MethodNameAndSignature` from a hello world, which allows trimming pretty much all of the type loader.
...because someone might want to put a Hello World (compiled with the default compiler settings) on a floppy. Of course we can go smaller if one starts disabling features like globalization or stack traces. But the defaults are interesting.
The theme is: type loader should not be necessary in a Hello World and we should be able to trim it.
[ ] Limit impact of reflectable Invoke methods #83066TryGetGenericMethodComponents
into two overloads #84156 This is keeping around MethodSignature support that needs type loader to do things like Equals.runtime/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs
Lines 893 to 895 in c9a7a2d
We should delete those lines and in the compiler emit what the else branch will handle. This will be a net improvement (search for "file format limitation" in the AOT compiler sources to find spots that deleting this will also fix)
With the above (and hacks for the last two), I see default Hello World at 1.46 MB, down from 1.77 MB.
The text was updated successfully, but these errors were encountered: