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鈥檒l 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

Closed
7 tasks done
MichalStrehovsky opened this issue Mar 7, 2023 · 1 comment 路 Fixed by #84156
Closed
7 tasks done

馃捑 Bringing the size of Native AOT Hello World under 1.44 MB #83069

MichalStrehovsky opened this issue Mar 7, 2023 · 1 comment 路 Fixed by #84156

Comments

@MichalStrehovsky
Copy link
Member

MichalStrehovsky commented Mar 7, 2023

...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.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 7, 2023
@ghost
Copy link

ghost commented Mar 7, 2023

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

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.

Author: MichalStrehovsky
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

@MichalStrehovsky MichalStrehovsky added this to the Future milestone Mar 7, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Mar 7, 2023
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this issue Mar 29, 2023
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.
jkotas pushed a commit that referenced this issue Mar 30, 2023
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.
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this issue Mar 31, 2023
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.
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 31, 2023
MichalStrehovsky added a commit that referenced this issue Mar 31, 2023
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.
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Mar 31, 2023
@ghost ghost locked as resolved and limited conversation to collaborators May 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant