Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
pirunxi committed Jan 24, 2024
1 parent dcb2913 commit 8c43c09
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 52 deletions.
17 changes: 0 additions & 17 deletions docs/business/ilinterpreter.md

This file was deleted.

8 changes: 3 additions & 5 deletions docs/business/metadataoptimization.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 元数据内存优化
# 元数据优化

HybridCLR执行代码过程中并不会额外多占用内存,但加载assembly的元数据占据了大量内存。对于一些内存有较大压力的场合(如微信小游戏),这可能是个问题。
针对此情况,所有商业化版本显著优化了元数据内存。
Expand All @@ -8,7 +8,8 @@ HybridCLR执行代码过程中并不会额外多占用内存,但加载assembly
- 使用完全泛型共享技术
- 优化加载补充元数据程序集内存
- 优化热更新程序集元数据内存
- **TODO** 提供基于原始IL指令的解释器

另外显著优化了Assembly.Load加载热更新程序集的时间,**商业化版本的加载耗时为社区版本的30%**


**根据目前的测试结果,在64位平台,商业化版本相比社区版本大约节省了 `{补充元数据总大小} * 4 + {热更新程序集总大小} * 1.8` 内存。**
Expand Down Expand Up @@ -65,6 +66,3 @@ Il2CppClass、MethodInfo及翻译后指令占据的内存,此部分延迟初
![aot-metadata-dll-rate](/img/memory-optimization/assembly-load-rate.jpg)


## 基于原始IL指令的解释器

不再需要运行时转换为寄存器指令集,节省了大量指令内存。缺点是明显降低了解释性能。

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,66 @@
# Metadata optimization

HybridCLR does not occupy additional memory when executing code, but loading assembly metadata occupies a large amount of memory. This may be a problem for some situations where there is a lot of memory pressure (such as WeChat mini-games).
For this situation, all commercial versions have significantly optimized metadata memory.
For this situation, all commercial editions have significantly optimized metadata memory.

Optimize memory usage from several aspects:

- Use fully generic sharing technology.
- Optimize the memory occupied by loading supplementary metadata assemblies
- Hot update assembly metadata optimization
- **TODO** provides an interpreter based on raw IL instructions
- Use fully generic sharing technology
- Optimize loading of supplementary metadata assembly memory
- Optimize hot update assembly metadata memory

In addition, the time for Assembly.Load to load hot-updated assemblies has been significantly optimized. **The loading time of the commercial edition is 30% of that of the community edition**.


**According to the current test results, on the 64-bit platform, the commercial edition saves approximately `{Total size of supplementary metadata} * 4 + {Total size of hot update assembly} * 1.8` compared to the community edition. **

For the WebGL platform (including WeChat mini games), since the faster (smaller) build option can be turned on, the package body will be further reduced (about 1-2 times the size of all aot dlls), resulting in a significant reduction in memory usage.
For most projects, the commercial edition can ultimately reduce the memory of the WebGL platform by nearly 50-100M or more.

## Fully generic sharing

Completely eliminating supplementary metadata memory (about 3-4 times the size of the dll). The disadvantage is that full generic sharing is only supported from 2021 onwards
Completely omitting supplementary metadata memory, it is about 4 times the size of the dll. The disadvantage is that full generic sharing is only supported from 2021 onwards. After turning on full generic sharing, the package body can be significantly reduced (reducing the compiled size of managed code by about 30-40%).

## Optimize supplementary metadata memory

We tested the memory consumption after supplementing metadata for common aot assemblies. The memory consumed by the community edition is about 4 times the size of the dll; the commercial edition consumes about 1.3 times when full generic sharing is not enabled;
After the commercial edition turns on full generic sharing, this item does not need to be supplemented with metadata, so this item is 0. Compared with the community edition, the commercial edition reduces memory by **67%** (100% when full generic sharing is enabled).

**detailed data**:

![aot-metadata-data](/img/memory-optimization/aot-metadata-data.jpg)


**Memory consumption**:


![aot-metadata-memory](/img/memory-optimization/aot-metadata-memory.jpg)

**Memory consumption/dll size**:

![aot-metadata-dll-rate](/img/memory-optimization/aot-metadata-dll-rate.jpg)


## Optimize hot update assembly memory

We tested the memory consumed by common plugins after loading in interpreted mode. The memory consumed by the community edition is about 4.7 times the size of the dll, and the commercial edition is 2.9 times. The commercial edition uses **39%** less memory than the community edition.

:::tip

This data does not include runtime latency data
The memory occupied by Il2CppClass, MethodInfo and translated instructions, the delayed initialization memory of this part is about 2.9-3.5 times the size of the dll. The final metadata memory consumed is 7.6-8.2 times for the community edition and 5.8-6.4 times for the commercial edition.
The commercial edition reduces memory by approximately **25%** compared to the community edition.

:::

## Optimize the memory occupied by loading supplementary metadata assemblies
**detailed data**:

The memory occupied during the loading process is optimized from 3-4 times the size of the supplementary metadata dll to about 1.2 times. This optimization takes effect on all Unity versions.
![aot-metadata-data](/img/memory-optimization/assembly-load-data.jpg)

## Hot update assembly metadata optimization
**Memory consumption**:

Reuse metadata to the greatest extent possible. Compared with the community version, it solves the problem of multiple allocation and leakage of Il2CppType memory.
![aot-metadata-memory](/img/memory-optimization/assembly-load-memory.jpg)

## Interpreter based on raw IL instructions
**Memory consumption/dll size**:

Runtime conversion to a register instruction set is no longer required, saving a large amount of instruction memory. The disadvantage is that it significantly reduces the interpretation performance.
![aot-metadata-dll-rate](/img/memory-optimization/assembly-load-rate.jpg)
1 change: 0 additions & 1 deletion sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const sidebars = {
'business/metadataoptimization',
'business/basiccodeoptimization',
'business/basicencryption',
'business/ilinterpreter',
'business/accesspolicy',
'business/businesscase',
{
Expand Down

0 comments on commit 8c43c09

Please sign in to comment.