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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mono AOT image size profiling #82101

Open
Tracked by #80938
kotlarmilos opened this issue Feb 14, 2023 · 9 comments
Open
Tracked by #80938

Mono AOT image size profiling #82101

kotlarmilos opened this issue Feb 14, 2023 · 9 comments
Assignees
Milestone

Comments

@kotlarmilos
Copy link
Member

Description

Size investigation of Mono AOT binaries relies on profiling tools like bloaty and otool which provide good insight about content of a binary. However, even with such tools, it is not straightforward to identify if data are redundant between different AOT images linked into a single binary.

For example, it might be beneficial to find methods that are duplicated in different AOT images. Also, it might be beneficial to preview methods info table, methods to llvm table, PLT and GOT entries, number of patches per method, etc.

The idea is to extend #79551 to output method code size and number of patches in addition to method name. It could output such data per AOT image and aggregated data with redundancies for a binary. It should help us identify redundant data in AOT images and allow us to be more data-driven.

This PR should collect all relevant data needed for Mono AOT size profiling and check if such mechanism has been already implemented or drafted. Ideas on what could be included into the Mono AOT size profiling are more than welcome.

/cc: @lambdageek @vargaz @fanyang-mono @ivanpovazan @jandupej @LeVladIonescu @SamMonoRT

@ivanpovazan
Copy link
Member

/cc: @lateralusX

@lateralusX
Copy link
Member

size of per method unwind data is also interesting to include. Mono uses its own unwind format and I know that we get duplication in that space since the target platform also include platform specific unwind data per method. When running in llvmonly mode (like WASM), we fallback to platform specific unwind data since we utilize C++ unwinder, so that shouldn't carry the additional Mono unwind data since we use stock LLVM tooling not capable of emitting Mono specific unwind data.

@kotlarmilos
Copy link
Member Author

size of per method unwind data is also interesting to include. Mono uses its own unwind format and I know that we get duplication in that space since the target platform also include platform specific unwind data per method. When running in llvmonly mode (like WASM), we fallback to platform specific unwind data since we utilize C++ unwinder, so that shouldn't carry the additional Mono unwind data since we use stock LLVM tooling not capable of emitting Mono specific unwind data.

Thanks for the suggestion! Trying to understand a use case where Mono specific unwind data are redundant. When running in llvmonly mode, Mono specific unwind data are not necessary as platform specific unwind data are used due to utilization of C++ unwinder, right?

@lateralusX
Copy link
Member

lateralusX commented Feb 16, 2023

Yes llvmonly relies on C++ unwinder so shouldn't add additional unwind data to image. AFAIK llvmonly uses a shadow stack on platforms where it can't take context meaning that prolog/epilog push/pop information about current frame in order to do a stackwalk when needed, but all unwinding is done using C++ exception handling.

When using Mono's LLVM backend we have customization that will emit generated unwind info into Mono specific format for Mono unwinder, but I believe we would also get OS specific unwind info in that case since OS needs to unwind each compiled method as well using the unwind info format used by OS when building through LLVM. When using our JIT AOT compiler we generate dwarf unwind info and setup the needed OS unwind info as part of generating the image, but on platform that doesn't use dwarf (windows) we would end up with both Mono unwind info as well as OS specific unwind info per function.

@kotlarmilos
Copy link
Member Author

The profiler could output the following in a file:

  • methods/extra methods/trampolines - assembly_name method_token method_name method_signature flags code_size number_of_patches unwind_info_size
  • types - class_token class_name vtable_size
  • got and plt entries - entries size
  • methods to llvm table - entries size

There are two options -- profiling during the compilation and profiling a binary. Profiling during the compilation would require changes across AOT compiler to collect all necessary data. Profiling a binary would rely on Mono API and could be a separate source file.

@kotlarmilos
Copy link
Member Author

Also, it would be good to revise available options. @mdh1418 is there a similar tool that we can use for size profiling?

@mdh1418
Copy link
Member

mdh1418 commented Mar 1, 2023

Also, it would be good to revise available options. @mdh1418 is there a similar tool that we can use for size profiling?

Not sure if these can be used for profiling the size of mono aot images, but I had previously used dotnet trace to profile what methods were hit when an app ran in conjunction with coreclr's dotnet-pgo tool to specifically AOT hot methods. #70851 and #70194 descriptions exemplify how the two tools can be used.

@kotlarmilos
Copy link
Member Author

Thanks, we will check it out. Also, there is aot_dump that outputs emitted methods, PLT and GOT entries.

if (acfg->aot_opts.dump_json)
aot_dump (acfg);

It could be enriched with the above-mentioned properties.

  • methods/extra methods/trampolines - assembly_name method_token method_name method_signature flags code_size number_of_patches unwind_info_size
  • types - class_token class_name vtable_size
  • got and plt entries - entries size
  • methods to llvm table - entries size

@kotlarmilos
Copy link
Member Author

Size profiling tool for Native AOT binaries - https://github.com/MichalStrehovsky/sizoscope

@kotlarmilos kotlarmilos modified the milestones: Future, 9.0.0 Jul 13, 2023
@kotlarmilos kotlarmilos modified the milestones: 9.0.0, Future Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants