ES6 Collections in V8: There's Neon Inside
summary
V8 implements ES6 Map and Set as a custom deterministic hash table: C++ arrays of buckets with packed entry triples, capacity always a power of two, load factor 0.5, and resizing that doubles or halves capacity (initial 4, max ~17M on 64-bit). Typical operations are average O(1) (worst-case O(n)); memory cost is roughly 29 MB per million Map entries (≈20 MB for Set). Weak collections are handled ephemeron-style integrated with the tricolor garbage collector, which can make cleanup much more expensive when reference cycles exist.
AI-written summary · about
chapters (9)
- 0:00Introduction
- 3:41ES6 collections overview in V8
- 8:07Deterministic hash table algorithm
- 15:17Map and Set implementation in V8
- 21:25Time and space complexity
- 21:48WeakMap and WeakSet in V8
- 25:41Garbage collection for WeakRef
- 31:15WeakMap versus WeakRef
- 31:35Conclusion and resources
related talks
22mMastering JavaScript Collections: Arrays, Maps, Sets, and Beyond
24mDemystifying V8 and JavaScript Performance
42mKolekcje, czyli jak silnik chrome V8 radzi sobie z danymi
30mV8 internals for JS developers
26mThe Hitchhiker's Guide to All Things Memory in Javascript
31mJavaScript memory management: Visual Guide
27mweak collections, ephemerons, and private fields by Sigurd Schneider | JSCAMP 2019
27mThe Life of a JavaScript Feature in V8 ft. TypedArrays
