Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

MichalStrehovsky
Copy link
Member

@MichalStrehovsky MichalStrehovsky commented 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.

Cc @dotnet/ilc-contrib

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
Copy link

ghost commented Mar 31, 2023

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

Issue Details

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.

Author: MichalStrehovsky
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@MichalStrehovsky
Copy link
Member Author

Hm, we still have the type loader on Linux. At least two reasons:

  1. ConsolePal uses a multi-dim array on Linux and multi-dim array construction has this piece of code to handle a dumb IL-level corner case.
    if (rank == 1)
    {
    // Multidimensional array of rank 1 with 0 lower bounds gets actually allocated
    // as an SzArray. SzArray is castable to MdArray rank 1.
    Type elementType = Type.GetTypeFromHandle(new RuntimeTypeHandle(eeType.ArrayElementType))!;
    return RuntimeImports.RhNewArray(elementType.MakeArrayType().TypeHandle.ToEETypePtr(), pDimensions[0]);
    }

    MakeArrayType needs the type loader in theory. (In practice, the MethodTable for this was created by the compiler, we just need to find it in a hashtable. Still annoying though.)
  2. This one is really annoying:
    image
    Boils down to "we have a delegate to something that takes something with a ValueTuple over a reference type, which means we need to make the target reflectable, which means we need a type loader template for all the arguments and the template needs the equality comparer infrastructure for the cctor". This is what I was trying to "fix" in Limit impact of reflectable Invoke methods #83066 but then it went away on its own on Windows (the delegate is a SpanAction so it would conveniently go away).

@MichalStrehovsky
Copy link
Member Author

In practice, the MethodTable for this was created by the compiler, we just need to find it in a hashtable.

Ah, nope. We could still be in some shared code and the MdArray handle was template-type-loaded. So we might need to template-type-load the SzArray.

We'll have to live with this.

I'll update the Linux baseline size to not expect the template type loader saving.

@jkotas
Copy link
Member

jkotas commented Mar 31, 2023

Ah, nope. We could still be in some shared code and the MdArray handle was template-type-loaded. So we might need to template-type-load the SzArray.

We can teach the JIT to use a different JIT helper for MD arrays that have rank 2 or more. The JIT helper for this case would not have this dependency.

@jkotas
Copy link
Member

jkotas commented Mar 31, 2023

This one is really annoying:

We can fix this one by calling FastAllocateString directly. We are calling FastAllocateString directly in System.Globalization in number of places, so one more is not a big deal.

@MichalStrehovsky
Copy link
Member Author

We can teach the JIT to use a different JIT helper for MD arrays that have rank 2 or more. The JIT helper for this case would not have this dependency.

I was afraid you would suggest this :).

This one is really annoying:

We can fix this one by calling FastAllocateString directly. We are calling FastAllocateString directly in System.Globalization in number of places, so one more is not a big deal.

Another alternative would be delaying making the delegate targets reflectable: #82607 (comment). But FastAllocateString is even more savings.

@MichalStrehovsky MichalStrehovsky merged commit 9c0d9cd into dotnet:main Mar 31, 2023
@MichalStrehovsky MichalStrehovsky deleted the split branch March 31, 2023 08:06
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this pull request Apr 1, 2023
MdArray rank1 with all-zero lower bounds gets actually allocated as an SzArray. On Native AOT this means we need to spin up to the type loader to potentially load the new type. Split this expensive (and impossible-to-express-in-C#) thing into a separate helper so we can trim the type loader.

dotnet#84156 (comment)
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this pull request Apr 1, 2023
A delegate with a ValueTuple over a reference type triggers generation of type loader data structures to load arbitrary ValueTuples over reference types at runtime. The replacement is a lot less expensive.

dotnet#84156 (comment)
jkotas pushed a commit that referenced this pull request Apr 1, 2023
A delegate with a ValueTuple over a reference type triggers generation of type loader data structures to load arbitrary ValueTuples over reference types at runtime. The replacement is a lot less expensive.

#84156 (comment)
jkotas pushed a commit that referenced this pull request Apr 3, 2023
MdArray rank1 with all-zero lower bounds gets actually allocated as an SzArray. On Native AOT this means we need to spin up to the type loader to potentially load the new type. Split this expensive (and impossible-to-express-in-C#) thing into a separate helper so we can trim the type loader.

#84156 (comment)
@ghost ghost locked as resolved and limited conversation to collaborators Apr 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

💾 Bringing the size of Native AOT Hello World under 1.44 MB
2 participants