-
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
Deduplication of symbols by using dedup/linkonce features #80419
Comments
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsDescriptionWhen Mono AOT compiler encounters a generic instance that is not handled by generic sharing, it will emit a code for the instance. If the same instance is encountered during compilation in multiple assemblies, the code will be emitted multiple times, increasing code size. SolutionsThere are at least two possible solutions to this problem. Dedup by Mono AOT compilerIt compiles instances into a separate AOT image and consists of two phases. Linkonce by LLVMIf two functions have the same name and they are marked linkonce, then the linker is allowed to throw away all copies except one. Experimental resultsList of methods In Mono iOS sample app that can be deduplicated. Estimated size reduction is 400kb. Deduplication of symbols is currently not enabled in WASM and iOS. TasksList of tasks that needs to be addressed in order to enabled it in WASM and iOS:
|
Update: The dedup feature can be enabled in HelloiOS app in non-LLVM debug configuration. To enable it in release mode and with LLVM, the updated list of tasks need to be resolved. Current implementation doesn't cover cases where both shared method and its inflated instances could be deduplicated. During the compilation, the shared method is emitted in corresponding AOT image while inflated instances are emitted in dedup AOT image. During the runtime, the shared method can't be retrieved as it was searched in the dedup AOT image. Here is an example. During the compilation, the following list of inflated instances emitted in the dedup AOT image.
During the runtime, Furthermore, In release configuration, during the runtime HelloiOS with LLVM enabled throws while executing method wrappers. During the debugging, the implementation was changed to emit all methods in corresponding AOT images and to have an empty dedup AOT image linked into a binary. The same error occurred, which could lead to having an issue with segments offset of AOT images in the binary. Further investigation is needed to narrow down the specific causes. /cc: @vargaz @lambdageek |
You might be able to fix this by adding |
What would be a good approach to add it? |
is_byreflike is computed when the class is created i.e. in mono_class_create_from_typedef () so it should be set correctly. |
Let me check if for
If LLVM is enabled the application throws in both release and debug configurations. When using debug configuration, runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs Line 1566 in 8b2a920
Similarly, when using release configuration, runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/TaskAwaiter.cs Line 140 in 8b2a920
In both cases, it fails when using default or global variable. The following direct call transformation is causing such issues with LLVM. @vargaz @lambdageek Any ideas why is it happening? runtime/src/mono/mono/mini/aot-compiler.c Lines 6512 to 6552 in 8b2a920
Overall, with proper retrieval of |
@kotlarmilos nice progress! |
With proper code changes it works in all configurations. We have to find appropriate fix for |
Description
When Mono AOT compiler encounters a generic instance that is not handled by generic sharing, it will emit a code for the instance. If the same instance is encountered during compilation in multiple assemblies, the code will be emitted multiple times, increasing code size.
Solutions
There are at least two possible solutions to this problem.
Dedup by Mono AOT compiler
It compiles instances into a separate AOT image and consists of two phases.
Dedup-skip
flag is used when compiling assemblies, and it disables emitting code of dedup-able methods.Dedup-include
flag is used when compiling dummy assembly where all assemblies are compiled together, and it enables emitting code of dedup-able methods only.Linkonce by LLVM
If two functions have the same name and they are marked linkonce, then the linker is allowed to throw away all copies except one.
Experimental results
List of methods In Mono iOS sample app that can be deduplicated. Estimated size reduction is 400kb.
Proposed change for enabling deduplication in Mono iOS sample app.
Deduplication of symbols is currently enabled in WASM.
The text was updated successfully, but these errors were encountered: