Question Details

No question body available.

Tags

javascript benchmarking v8 for-in-loop object-keys

Answers (1)

Accepted Answer Available
Accepted Answer
March 4, 2026 Score: 5 Rep: 6,840 Quality: High Completeness: 80%

TL;DR: It's a missing optimization in V8's optimizing compilers (Turbofan and Maglev). I've created a bug on the Chromium tracker, and I'll fix it in the next few days if I have enough time. (and also, your benchmark doesn't benchmark what you think it does, cf the latest section of this answer)

Technical details:

The missing optimization is that V8 doesn't constant-fold loads from the script context when compiling a closure whose code has been instantiated multiple times. Here is an example:

const o = { a : 42 };

function makeclosure() { return () => o.a; }

let closure1 = make
closure();

%PrepareFunctionForOptimization(closure1); closure1(); //make_closure()(); //