-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Trimming Tools in .NET 8 #78671
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas Issue DetailsThere are two categories of tools that would help users with trimming
For (1), users could use the tool to examine the size of items after trimming and see what's taking up the most space. For (2), users could find out what's keeping a particular type or member around, and then remove the roots.
|
In case this helps drive features/solutions here, the most helpful tools I've found are: App Size
Trimming rootsFor seeing "why" a chunk of code is included in the app, the easiest approach I found is:
<PublishAot>false</PublishAot>
<PublishTrimmed>true</PublishTrimmed>
<SelfContained>true</SelfContained>
<TrimMode>full</TrimMode>
<DynamicCodeSupport>false</DynamicCodeSupport>
<EventSourceSupport>false</EventSourceSupport>
This usually finds 80-90% of the reasons why a certain method/class is required by the app. When this doesn't tell me why, then I end up using https://github.com/dotnet/linker/tree/main/src/analyzer as my next option. |
A 'readelf'-like utility that prints information about assemblies (#73913 (comment)) could be useful for App size. If it does not already exist, can this be added as a task ? sizebench seems to be a windows-only utility. |
@agocke I'm not specifically familiar with either of those tools but my initial impression is that they both present a more or less flat list (albeit with granular categories). I guess the two main things I'd want from a solution are:
|
I definitely don't think a UI is worth it at this point. Dumping the information to a text file or to stdout is good enough to start. stdout/text file also allows for easy diffing between 2 apps/versions. I've found myself looking at diffs a lot lately. For example, if I add component X, I see my app size jump xxMB. What were all the changes between the two versions? |
My vote is also for text output |
Preferably, structured text output (i.e. json or csv). |
I would imagine the output format to be configurable. For example bloaty has this:
|
text output should be fine.. |
@agocke
|
For anyone interested on working on this, I have an incomplete write-up of a potential design for this kind of tool. It might be useful as a starting point: sbomer/linker@961474c?short_path=bcecbad#diff-bcecbad3970ec34a98732056ca2a36fdd2c7cfb1f7c285be0329d5116f6cf56c |
We also have a lossy text format that has this info. <?xml version="1.0" encoding="utf-8"?>
<ObjectNodes>
<ConstructedEEType Name="??_7NAotHello_Program@@6B@" Length="56" Hash="d4817aa5497628e7c77e6b606107042bbba3130888c5f47a375e6179be789fbb" />
<ConstructedEEType Name="??_7System_Console_Microsoft_CodeAnalysis_EmbeddedAttribute@@6B@" Length="56" Hash="d4817aa5497628e7c77e6b606107042bbba3130888c5f47a375e6179be789fbb" />
...
</ObjectNodes> It loses a bunch of information about assemblies or namespaces (well, it's still there, but behind mangling). As the output of the compiler, we need something that doesn't lose any information. Either a text format that will be very complex, or binary format. We already have the binary format. I'm open to having a text format, but it will not be easy to parse. E.g. for a method, we need to capture: Owning type name, namespace, assembly, including any generic instantiation parameters if the type is generic. If the generic parameters are specified, we need to be able to also map them to things like name, namespace, assembly, etc. Name of the method. If the method is generic, also generic arguments to the method in a form where we can easily identify what type that is (assembly name, namespace, if it's constructed like an array, the deconstruction of it etc.). Methods can have overloads so we also need the signature, encoding the types of all parameters. I'm imaging future tools that might be able to take you to the source code of the problematic thing. So we need the full fidelity. I see an IL based binary format as best equipped for this. Tools can make various textual "views" of this information. |
So that we have a place to work and contribute code, I've created a new branch |
I've added the existing MstatDump in dotnet/runtimelab#2238 |
I've built a GUI tool to inspect/diff/rootcause Native AOT size. Repo here: https://github.com/MichalStrehovsky/sizoscope. Personal repo since it's my vacation project and "code reviews" and "driving consensus" is the opposite of a vacation. |
thank |
Closing out as we don't plan any further work in .NET 8. |
There are two categories of tools that would help users with trimming
For (1), users could use the tool to examine the size of items after trimming and see what's taking up the most space.
For (2), users could find out what's keeping a particular type or member around, and then remove the roots.
The text was updated successfully, but these errors were encountered: