Inside V8: weak collections, ephemerons, and private fields
Sigurd Schneider at JSCamp 2019
This talk explores the implementation and performance characteristics of weak collections (WeakMap, WeakSet, WeakRefs) in V8, the JavaScript engine that powers Chrome and Node.js. The entries of weak collections have ephemeron semantics: an entry is cleared automatically once the key of the entry is no longer referenced anywhere else. This feature makes weak collections one option for implementing private fields. This talk explains what JavaScript weak collections are, and when to use them. We will also explore private fields, how they behave, and how they can be polyfilled with weak collections. Finally, we'll discuss performance and memory challenges for weak collections in the V8 JavaScript engine.