BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Profiling and Optimizing V8 Memory Consumption

Profiling and Optimizing V8 Memory Consumption

Bookmarks

For the last few months, the V8 team has focused on reducing the memory consumed by the V8 engine, including work on the new Ignition interpreter, and improvements to V8’s parser and compilers. A key enabler of this process was profiling V8 memory usage using specific tools against a benchmark, as explained by V8 engineers Ulan Degenbaev, Michael Lippautz, Hannes Payer, and Toon Verwaest.

To reduce V8’s memory footprint, the V8 team monitored its two heaps – the C++ and the JavaScript heap – using a new feature in Chrome 54: the --trace-gc-object-stats flag, that makes V8 dump memory-related statistics to the console. That output is then visualized using a custom tool, the V8 heap visualizer, which shows a timeline-based view for both heaps and provides a detailed breakdown of the memory usage of certain data types. Another tool that the V8 team used for this kind of analysis is Chrome’s Trace Event Profiling Tool, which is available under about:tracing.

What memory analysis showed is that one of the main factors determining the JavaScript heap size is the balance between latency and memory consumption of the garbage collector. You can improve latency by reserving more memory to the heap to avoid frequent GC invocations. This may however be a problem for low-memory devices and lead to crashes or suspended apps. To strike a better balance between latency and memory consumption, the V8 team has introduced a new memory reduction mode that favors more frequent collections and reduces memory fragmentation through more aggressive compactions. The new memory reduction more brought an overall 50% reduction in V8 heap size on a reference benchmark. Another optimization that has been introduced consisted in reducing the V8 heap page size from 1M to 512K, benefiting both overall memory usage and memory fragmentation.

The V8 team could also reduce the C++ heap size by improving background parsing, which allows V8 to parse script while the page is still being loaded. In fact, as the memory visualization tool showed, the background parser would keep a heap zone alive long after the code had been compiled, instead of releasing it immediately. Additionally, the V8 parser is now using a more aggressive strategy to pack fields in the abstract syntax tree nodes it generates, whereas the standard C++ packing was relied upon previously. Benchmarking showed a peak zone memory reduction of about 40% on average.

All improvements described above will be available in Chrome 55, expected to become available in December.

Rate this Article

Adoption
Style

BT