dotnet / corert

This repo contains CoreRT, an experimental .NET Core runtime optimized for AOT (ahead of time compilation) scenarios, with the accompanying compiler toolchain.
http://dot.net
MIT License
2.91k stars 511 forks source link

Base class library size on disk footprint workitems #5013

Open MichalStrehovsky opened 6 years ago

MichalStrehovsky commented 6 years ago

I spent some time looking into why an optimized Hello World is 3.8 MB big on Windows. There are two ways to look at this problem: what we do in the compiler to make it this big, and what we do in the class libraries that forces it to be so big. This issue tracks the latter.

With a set of hacks here Hello World can go down to about 2.4 MB. I was focusing mostly on getting the reflection stack out of the binary.

The problems:

There are also some other opportunities I didn't measure yet:

jkotas commented 6 years ago

Someone will box and enum and someone will call a ToString. We'll need to generate this method. It better be lightweight.

Are you trying to get rid of dependency on native metadata completely? I would think that saving the backing data for enums in the native metadata should be fine. Maybe the real problem here is that there is too much code required to fetch the enum values and names from native metadata.

ETW tracing enabled Globalization support

These maybe candidates for readonly-value overrides implemented by Mono AOT: https://github.com/mono/mono/blob/50fa04c1365f68f309c6d0613c96672deb0d07fc/man/mono.1#L274 . The basic idea is that you place the call to the code you want to exclude behind a property and you tell the compiler what this property is going to return. It would be nice to do this optimization in IL Linker as an optional pass since it is generally applicable. Though this one is low-level and policy-free enough that we can live with it in the ILCompiler too.

For globalization, we should base it on https://github.com/dotnet/corefx/blob/master/Documentation/architecture/globalization-invariant-mode.md. (It did not existed when the Dummy globalization was added.)

ResourceManager

I would be nice to have an option to replace the localizable error strings with hardcoded single language messages; or no errors strings at all. Again, it would be nice to do this as optional pass in ILLinker.

IsByRefLike. This is implemented as a custom attribute search

It should be fetched from EEType when we have one.

MichalStrehovsky commented 6 years ago

Maybe the real problem here is that there is too much code required to fetch the enum values and names from native metadata

This. To do a ToString, the higher level reflection stack will do a custom attribute walk to check for the Flags attribute. Checking for attributes is super expensive because it involves resolving ConstructorInfos and that's a lot of code. I would want us to have a low level fast path that uses the MetadataReader directly.

It should be fetched from EEType when we have one.

This is in a code path where all we have is a System.Type that might not have an EEType. So we need to compile the code that can deal with that. Which involves custom attribute search and those are expensive.