raw
current commit
261004.7 · deps: update V8 to 15.2.124.38

Heap Compaction in V8

Compaction is a phase of the Major Garbage Collector (Mark-Sweep-Compact) used to resolve memory fragmentation in the Old Generation and other spaces.

Overview

Over time, as objects are allocated and freed, the heap can become fragmented—full of small free spaces that are too small to satisfy new allocation requests. Compaction solves this by moving live objects closer together, creating large contiguous free spaces.

The Compaction Pipeline

1. Identification of Evacuation Candidates

V8 does not compact the entire heap at once, as that would cause unacceptably long pause times. Instead, it identifies specific pages as “evacuation candidates” in CollectEvacuationCandidates:

2. Parallel Evacuation

The actual moving of objects happens in parallel to utilize multiple cores:

3. Forwarding Addresses

When an object is moved to a new location:

4. Pointer Updating

After all objects have been moved, V8 must update all references to point to the new locations in UpdatePointersAfterEvacuation:

Additional Compaction Areas

File Structure