How I Made V8's Array.prototype.flat Up to 20× Faster—and the Journey to a Large-Scale OSS Contribution
SessionTrack BJapanese
Slides
After seeing a post that JSC’s Array.prototype.flat was getting faster, I realized that the idea might also apply to V8. About a month later, my patch was merged into V8 14.7, making flat up to roughly 20 times faster across Chrome, Node.js, Deno, and runtimes built on V8.
The main topic is the optimization itself. V8 tracks array contents by internal ElementsKinds such as integer-only, float-containing, and hole-containing arrays. This information proves that an array containing no subarrays can skip traversal. The talk explains why flat was slow before, a two-pass approach that reduces memory allocation to one pass, the special hole-handling requirements, and the implementation in V8’s Torque language. It also covers proposing a change to v8-dev, Gerrit review, merging, and inserting code into a huge OSS project as an individual.

Yuta Nishi
A platform engineer working on product development. Loves the web, especially frontend development, TypeScript, and V8, with a particular interest in type puzzles and V8's array internals. Also enjoys exploring the history and specifications of the web, contributing to TSKaigi, writing technical articles on Zenn, and speaking at conferences.

