一句话:提出无需通信即可在多堆间最优分配内存的平方根堆上限规则,并在 V8 中显著降低内存或 GC 时间。
垃圾回收语言运行时通过调节堆上限来权衡内存占用与 GC 时间:上限越低越省内存,但 GC 时间越高。传统方法包括手工调参和按存活对象倍数设置的经验规则,却难以比较何者更优。本文提出一个将多个堆的堆上限同时设置的框架,关键洞察是每条堆上限规则都对应一种跨进程内存分配,而该分配可能次优。基于此,作者推导出最优“平方根”堆上限规则,能在给定总 GC 时间下最小化总内存使用;该规则无需堆间通信即可实现多堆协调。作者在 V8 中实现原型,真实网页上内存降低约 16.0% 且 GC 时间不变;内存密集基准上 GC 时间最多降低 30.0% 且总内存不变。
Garbage-collected language runtimes carefully tune heap limits to reduce garbage collection time and memory usage. However, there's a trade-off: a lower heap limit reduces memory use but increases garbage collection time. Classic methods for setting heap limits include manually tuned heap limits and multiple-of-live-size rules of thumb, but it is not clear when one rule is better than another or how to compare them. We address this problem with a new framework where heap limits are set for multiple heaps at once. Our key insight is that every heap limit rule induces a particular allocation of memory across multiple processes, and this allocation can be sub-optimal. We use our framework to derive an optimal "square-root" heap limit rule, which minimizes total memory usage for any amount of total garbage collection time. Paradoxically, the square-root heap limit rule achieves this coordination without communication: it allocates memory optimally across multiple heaps without requiring any communication between those heaps. To demonstrate that this heap limit rule is effective, we prototype it for V8, the JavaScript runtime used in Google Chrome, Microsoft Edge, and other browsers, as well as in server-side frameworks like node.js and Deno. On real-world web pages, our prototype achieves reductions of approximately 16.0% of memory usage while keeping garbage collection time constant. On memory-intensive benchmarks, reductions of up to 30.0% of garbage collection time are possible with no change in total memory usage.
@article{paperbot1430,
title = {Optimal heap limits for reducing browser memory use},
author = {Marisa Kirisame and Pranav Shenoy and Pavel Panchekha},
journal = {Proceedings of the ACM on Programming Languages},
volume = {6},
number = {OOPSLA2},
year = {2022},
doi = {10.1145/3563323}
}