Impact On the App Size
After integrating HybridCLR, there is a slight increase in package size, mainly due to the following components:
- The core code of HybridCLR, excluding MethodBridge.cpp.
- The bridge function file MethodBridge.cpp.
- The cpp code generated by il2cpp from the HybridCLR.Runtime.dll code.
Among these, the code in part 1 is less than 30,000 lines, and the code in part 3 is less than 2,000 lines, which have minimal impact on the final package size. The size of MethodBridge.cpp is calculated based on the AOT assemblies. Generally, the larger the AOT assemblies, the larger the MethodBridge.cpp file. Typically, depending on the complexity of the project’s AOT modules, the size of MethodBridge.cpp ranges from 2MB to 40MB.
We conducted a test project to measure the actual impact of HybridCLR on package size.
Testing
We tested the package size of an Android Armv8 platform APK built with Unity 2021.
The AOT portion of the test project fully 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 calculated the total size of the AOT module DLLs in the built APK: 12.0MB.
The hot-update portion of the test project includes the following:
- Unit test project code.
- Configuration code generated by Luban.
The compiled HotUpdate.dll is 1216KB. To ensure fairness, the hot-update DLLs in projects integrated with HybridCLR are compressed and included in the StreamingAssets package.
We compared the package size across the following eight scenarios:
- NotHybridCLR-NotHotUpdateCode: Without HybridCLR integration and without including HotUpdate code (HotUpdate is not part of AOT).
- HybridCLR-NotHotUpdateCode-NotMethodBridge: Integrated with HybridCLR, without HotUpdate code, and with an empty bridge function file.
- HybridCLR-NotHotUpdateCode-MethodBridge: Integrated with HybridCLR, without HotUpdate code, and with a normal bridge function file.
- NotHybridCLR-HotUpdateCode: Without HybridCLR integration and with HotUpdate code included (HotUpdate is part of AOT).
- HybridCLR-HotUpdateCode-NotMethodBridge: Integrated with HybridCLR, with HotUpdate code included (compressed HotUpdate.dll in the StreamingAssets package), and with an empty bridge function file.
- HybridCLR-HotUpdateCode-MethodBridge: Integrated with HybridCLR, with HotUpdate code included, and with a normal bridge function file.
- HybridCLR Ultimate Edition-NotHotUpdateCode-MethodBridge Integrated with HybridCLR Ultimate Edition, without HotUpdate code, and with a normal bridge function file.
- HybridCLR Ultimate Edition-HotUpdateCode-MethodBridge Integrated with HybridCLR Ultimate Edition, with HotUpdate code included, and with a normal bridge function file.
The test data is as follows:
Build Type | APK Size (KB) | global-metadata.dat (Uncompressed) | global-metadata.dat (Compressed) | libil2cpp.so (Uncompressed) | libil2cpp.so (Compressed) | HotUpdate.dll Size (Uncompressed, KB) | MethodBridge.cpp Size (KB) |
---|---|---|---|---|---|---|---|
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 |
|HybridCLR_UltimateEdition-NotUserCode-MethodBridge|31022|10078796|2905605|78643792|19935716|0|14837| |HybridCLR_UltimateEdition-UserCode-MethodBridge|32910|10893080|3103310|85964616|21622297|1206|15179|14861 |
Uncompressed
indicates the original size of the file within the APK, andCompressed
indicates the compressed size within the APK.
The original size of the hot-update code HotUpdate.dll is 1216KB, which is compressed to 200KB.
Based on the above test project, we can draw the following conclusions:
- The core part of HybridCLR, excluding MethodBridge.cpp, increases the package size by 196KB.
- The bridge function file increases the package size by approximately
{MethodBridge.cpp Size} * 0.049
. - For every additional size
S
of game code, an app without HybridCLR integration increases in size byS * 1.37
. - For every additional size
S
of game code, an app with HybridCLR integration increases in size byS * 0.2
. - For every additional size
S
of game code, the Ultimate Edition increases the package size byS * 1.56
. - When no update assemblies are included, the Ultimate Edition increases the package size by 32KB compared to the Community version.
Summary
Community, Professional, and Hot Reload Edition
Integrating HybridCLR increases the package size by 196k + {MethodBridge.cpp File Size} * 0.049
, but moving game code from AOT to hot updates can reduce the package size by {HotUpdate.dll Size} * 1.17
.
This means that if the hot-update code in a project exceeds 800KB-1500KB, integrating HybridCLR will result in a smaller final package size compared to not integrating it. The total package size reduction can be approximately calculated as HotUpdate.dll Size * 1.05
.
Ultimate Editionn
Integrating HybridCLR increases the package size by 228k + {MethodBridge.cpp File Size} * 0.049
.
Newly added code in the DHE assemblies will increase the package size by {New DHE Assembly Size} * 1.56
.
Moving game code from AOT to the DHE assemblies will increase the package size by {New DHE Assembly Size} * 0.19
.