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] Investigate performance impact of using interpreter as the default fallback for generics instead of GSHAREDVT methods #71482

Open
Tracked by #80938
ivanpovazan opened this issue Jun 30, 2022 · 6 comments

Comments

@ivanpovazan
Copy link
Member

While investigating app size differences between legacy and .NET 7 mono for iOS, it has been seen that GSHAREDVT methods take up around 5% of the __text size.
This can be observed by following the steps from the above-mentioned issue to generate binaries, and running bloaty with:

  • to get the total size:
bloaty -d segments,sections,symbols,compileunits --debug-file=dotnet/bin/iPhone/Release/net7.0-ios/ios-arm64/MySingleView.app.dSYM/Contents/Resources/DWARF/MySingleView dotnet/bin/iPhone/Release/net7.0-ios/ios-arm64/MySingleView.app/MySingleView > ../logs/dotnet_symbols_s.list

which shows 4.73Mb of the __text section

  • to get the size of GSHAREDVT methods:
bloaty -d segments,sections,symbols,compileunits --debug-file=dotnet/bin/iPhone/Release/net7.0-ios/ios-arm64/MySingleView.app.dSYM/Contents/Resources/DWARF/MySingleView dotnet/bin/iPhone/Release/net7.0-ios/ios-arm64/MySingleView.app/MySingleView --source-filter GSHAREDVT > ../logs/dotnet_symbols_gshared.list

which shows 258Ki of the __text section

Since these methods are large and slow, and are used only as a fallback when generic value type cannot be determined it would be valuable to investigate the impact of replacing them with the interpreter as the default fallback.

The impact of this change should be tested for:

  • correctness (dotnet/runtime test suite)
  • measured for size (bloaty) and speed (fullaotllvm runs of microbenchmarks) performance

cc @BrzVlad

@ghost
Copy link

ghost commented Jun 30, 2022

Tagging subscribers to this area: @BrzVlad
See info in area-owners.md if you want to be subscribed.

Issue Details

While investigating app size differences between legacy and .NET 7 mono for iOS, it has been seen that GSHAREDVT methods take up around 5% of the __text size.
This can be observed by following the steps from the above-mentioned issue to generate binaries, and running bloaty with:

  • to get the total size:
bloaty -d segments,sections,symbols,compileunits --debug-file=dotnet/bin/iPhone/Release/net7.0-ios/ios-arm64/MySingleView.app.dSYM/Contents/Resources/DWARF/MySingleView dotnet/bin/iPhone/Release/net7.0-ios/ios-arm64/MySingleView.app/MySingleView > ../logs/dotnet_symbols_s.list

which shows 4.73Mb of the __text section

  • to get the size of GSHAREDVT methods:
bloaty -d segments,sections,symbols,compileunits --debug-file=dotnet/bin/iPhone/Release/net7.0-ios/ios-arm64/MySingleView.app.dSYM/Contents/Resources/DWARF/MySingleView dotnet/bin/iPhone/Release/net7.0-ios/ios-arm64/MySingleView.app/MySingleView --source-filter GSHAREDVT > ../logs/dotnet_symbols_gshared.list

which shows 258Ki of the __text section

Since these methods are large and slow, and are used only as a fallback when generic value type cannot be determined it would be valuable to investigate the impact of replacing them with the interpreter as the default fallback.

The impact of this change should be tested for:

  • correctness (dotnet/runtime test suite)
  • measured for size (bloaty) and speed (fullaotllvm runs of microbenchmarks) performance

cc @BrzVlad

Author: ivanpovazan
Assignees: ivanpovazan
Labels:

area-Codegen-Interpreter-mono

Milestone: Future

@ivanpovazan
Copy link
Member Author

Similar results have been observed by measuring the size of the MAUI sample app built for ios-arm64 on .NET 7 which gives the following:

  • 7.6% of the __text section is taken by GSHAREDVT method variants

These results can be obtained with the following steps:

curl -o dotnet-sdk-7.0.100-preview.6.22316.8-osx-arm64.tar.gz https://dotnetbuilds.azureedge.net/public/Sdk/7.0.100-preview.6.22316.8/dotnet-sdk-7.0.100-preview.6.22316.8-osx-arm64.tar.gz
mkdir dotnet7
tar -xvf dotnet-sdk-7.0.100-preview.6.22316.8-osx-arm64.tar.gz -C dotnet7
cd dotnet7
./dotnet workload install maui --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json --source https://api.nuget.org/v3/index.json --from-rollback-file https://maui.blob.core.windows.net/metadata/rollbacks/7.0.0/preview.6.json
./dotnet new maui -n "MyMauiApp"
cd MyMauiApp
../dotnet publish -f net7.0-ios -r ios-arm64 -c Release

and retrieving the symbol sizes with bloaty:

  • to get the total size:
bloaty -d segments,sections,symbols --debug-file=bin/Release/net7.0-ios/ios-arm64/MyMauiApp.app.dSYM/Contents/Resources/DWARF/MyMauiApp bin/Release/net7.0-ios/ios-arm64/MyMauiApp.app/MyMauiApp -n 0 > MyMauiApp_symbols.list

which shows 23.2Mb of the __text section

  • to get the size of GSHAREDVT methods:
bloaty -d segments,sections,symbols --debug-file=bin/Release/net7.0-ios/ios-arm64/MyMauiApp.app.dSYM/Contents/Resources/DWARF/MyMauiApp bin/Release/net7.0-ios/ios-arm64/MyMauiApp.app/MyMauiApp -n 0 --source-filter GSHAREDVT  > MyMauiApp_GSHAREDVT_symbols.list

which shows 1.77Mb of the __text section

@SamMonoRT
Copy link
Member

Moving this to 8.0.0 with a possibility we may backport changes if this has significant perf improvements.

@SamMonoRT SamMonoRT modified the milestones: 7.0.0, 8.0.0 Aug 10, 2022
@jonathanpeppers jonathanpeppers moved this from Todo: App Size to Future: App Size in .NET 7 MAUI Performance Sep 15, 2022
@ivanpovazan
Copy link
Member Author

It is important to note that enabling interpreter also affects the final bundle size in the following ways:

  1. Including the interpreter code in the final app
  2. Including additional wrappers/trampolines for switching between AOTed and interpreted code
  3. IL code from the assemblies cannot be stripped out (by ILStrip) as it needs to be interpreted

The first two points should not have a big impact on the overall size (at least compared to the size of GSHAREDVT methods). However, the last point has significant impact.

For example: System.Private.CoreLib used for building a MAUI iOS template application has the following sizes after trimming and after IL stripping:

Trimmed Trimmed and IL stripped
1762304 983040

Considering just System.Private.CoreLib it means that the application bundle with interpreter enabled would increase for at least 0,78Mb, making this approach not feasible for size savings.

However, it might be possible to make ILStripping more sophisticated and strip all the IL code except for the generic methods for which MonoAOT would generate GSHAREDVTs. It might be beneficial to repeat the experiment once such improvements are introduced.
Similar requirement for Android has be reported here: #44855

@lewing
Copy link
Member

lewing commented May 24, 2023

@kg @vargaz I wonder how the jiterpreter would compare against gsharedvt on browser-wasm now? We don't ilstrip so there would be no size regression around keeping the il.

@ivanpovazan
Copy link
Member Author

Moving to 9.0.0

@ivanpovazan ivanpovazan modified the milestones: 8.0.0, 9.0.0 Jul 24, 2023
@ivanpovazan ivanpovazan 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

3 participants