Impact on App Package Size
The impact on package size after integrating HybridCLR mainly consists of the following parts:
- HybridCLR main code excluding MethodBridge.cpp
- Bridge function file MethodBridge.cpp code
- C++ code generated by il2cpp translating HybridCLR.Runtime.dll code
- Reduced binary code size after changing AOT assemblies to interpreted execution
Among these, part 1 has less than 30,000 lines of code, part 3 has less than 2,000 lines of code, and their impact on the final package size is minimal. MethodBridge.cpp is generated based on calculations from AOT assemblies. Generally speaking, the more code in AOT assemblies, the larger the MethodBridge.cpp file will be. Typically, depending on the complexity of the project's AOT modules, the MethodBridge.cpp file size ranges from 2M-40M.
We built test projects to test the actual impact of HybridCLR on package size.
Testing
We tested the size of Android Armv8 platform apk built in Unity 2021.
The AOT part of the test project completely includes the following frameworks and libraries:
- mscorlib, System, System.Core
- UnityEngine.dll, UnityEngine.CoreModule.dll, UnityEngine.UI.dll, UnityEngine.PhysicsModule.dll
- GameFramework framework
- HybridCLR.Runtime.dll
- Luban
- UniTask
- YooAsset
We counted the total size of AOT module dlls after building the apk: 12.0M in total.
The hot update part of the test project consists of the following components:
- Unit test project code
- Configuration code generated by Luban
The compiled HotUpdate.dll is 1216k. For fairness, projects integrating HybridCLR will compress the hot update dll and place it in StreamingAssets for packaging.
We compared the package sizes for the following 8 scenarios:
- NotHybridCLR-NotHotUpdateCode: No HybridCLR integration, no HotUpdate code included (i.e., HotUpdate not included in AOT)
- HybridCLR-NotHotUpdateCode-NotMethodBridge: HybridCLR integrated, no HotUpdate code included, bridge function file is empty
- HybridCLR-NotHotUpdateCode-MethodBridge: HybridCLR integrated, no HotUpdate code included, bridge function file normally generated
- NotHybridCLR-HotUpdateCode: No HybridCLR integration, HotUpdate code included (i.e., HotUpdate included in AOT)
- HybridCLR-HotUpdateCode-NotMethodBridge: HybridCLR integrated, HotUpdate code included (HotUpdate.dll compressed and placed in StreamingAssets for packaging), bridge function file is empty
- HybridCLR-HotUpdateCode-MethodBridge: HybridCLR integrated, HotUpdate code included, bridge function file normally generated
- HybridCLR Ultimate Edition-NotHotUpdateCode-MethodBridge: Ultimate Edition HybridCLR integrated, no HotUpdate code included, bridge function normally generated
- HybridCLR Ultimate Edition-HotUpdateCode-MethodBridge: Ultimate Edition HybridCLR integrated, HotUpdate code included, bridge function normally generated
Test data is as follows:
Build Method | Apk Size (K) | global-metadata.dat (uncompressed) | global-metadata.dat (compressed) | libil2cpp.so (uncompressed) | libil2cpp.so (compressed) | HotUpdate.dll Size (uncompressed) (K) | MethodBridge.cpp Size (K) |
---|---|---|---|---|---|---|---|
NotHybridCLR-NotHotUpdateCode | 30066 | 10087740 | 2980934 | 73383680 | 18954786 | 0 | 0 |
HybridCLR-NotHotUpdateCode-NotMethodBridge | 30262 | 10075360 | 2904652 | 74026488 | 19158769 | 0 | 0 |
HybridCLR-NotHotUpdateCode-MethodBridge | 30900 | 10075360 | 2904652 | 78450168 | 19905020 | 0 | 15082 |
NotHybridCLR-HotUpdateCode | 31718 | 10893056 | 3103289 | 79670208 | 20387018 | 1206 | 0 |
HybridCLR-HotUpdateCode-NotMethodBridge | 30531 | 10081232 | 2906522 | 74158928 | 19177165 | 1206 | 0 |
HybridCLR-HotUpdateCode-MethodBridge | 31259 | 10081232 | 2906522 | 78492496 | 19920506 | 1206 | 14861 |
HybridCLR Ultimate Edition-NotUserCode-MethodBridge | 31022 | 10078796 | 2905605 | 78643792 | 19935716 | 0 | 14837 |
HybridCLR Ultimate Edition-UserCode-MethodBridge | 32910 | 10893080 | 3103310 | 85964616 | 21622297 | 1206 | 15179 |
Uncompressed
refers to the original size of the file in the apk,Compressed
refers to the compressed size of the file in the apk
The original size of the hot update code HotUpdate.dll is 1216k, compressed to 200k.
Based on the above test project, we can roughly draw the following conclusions:
- The main part of HybridCLR excluding MethodBridge.cpp ultimately increased package size by 196k
- Bridge function files increased package size by approximately
{MethodBridge.cpp size} * 0.049
- For each new game code of size S, for apps without HybridCLR integration, package size increased by
S * 1.37
- For each new game code of size S, for apps with HybridCLR integration, package size increased by
S * 0.2
- For each new game code of size S, Ultimate Edition increased package size by
S * 1.56
- When no update assemblies are included, Ultimate Edition increases package size by 32K compared to community edition
Summary
Community Edition, Professional Edition, Hot Reload Edition
Integrating HybridCLR increases package size by 196k + {MethodBridge.cpp size}*0.049
, but moving game code from AOT to hot update can reduce package size by {hot update dll size}*1.17
times.
This means that if a project's hot update code exceeds 800K-1500K, the final package size after integrating HybridCLR will be smaller than without HybridCLR integration. The final package reduction can be roughly approximated using hot update dll size*1.05
.
Ultimate Edition
Integrating HybridCLR increases package size by 228k + {MethodBridge.cpp size}*0.049
. New code in DHE assemblies will cause an increase in package size of {new DHE assembly size}*1.56
.
Moving game code from AOT to DHE assemblies will increase package size by {new DHE assembly size}*0.19
.