Skip to main content
Version: Next

Impact on App Package Size

The impact on package size after integrating HybridCLR mainly consists of the following parts:

  1. HybridCLR main code excluding MethodBridge.cpp
  2. Bridge function file MethodBridge.cpp code
  3. C++ code generated by il2cpp translating HybridCLR.Runtime.dll code
  4. 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:

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 MethodApk 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-NotHotUpdateCode30066100877402980934733836801895478600
HybridCLR-NotHotUpdateCode-NotMethodBridge30262100753602904652740264881915876900
HybridCLR-NotHotUpdateCode-MethodBridge309001007536029046527845016819905020015082
NotHybridCLR-HotUpdateCode31718108930563103289796702082038701812060
HybridCLR-HotUpdateCode-NotMethodBridge30531100812322906522741589281917716512060
HybridCLR-HotUpdateCode-MethodBridge312591008123229065227849249619920506120614861
HybridCLR Ultimate Edition-NotUserCode-MethodBridge310221007879629056057864379219935716014837
HybridCLR Ultimate Edition-UserCode-MethodBridge329101089308031033108596461621622297120615179

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.