Performance of ES6 features relative to the ES5 baseline operations per second (2022)
3 points by gnyeki
3 points by gnyeki
It would be interesting to see results for the latest engines.
I found it surprising that constructs like for (var … of …)
are slower than their ES5 counterparts in almost all the major browser engines. Or at least they seem to have been in 2022.
iteration is slower than property access. https://gist.github.com/easrng/5ab2f2d49309d40462054a4beca1de5c
the fundamental design of iteration is slower that the alternatives: a for loop over an array is an indexed access and integer incrementation, and in-bounds integer access of an array was optimized in all engines 20 years ago.
a for(in) loop is also faster but the reasons are because it actually gets very close to to an array loop - the set of properties to lookup are cached, and for normal property access (at least in jsc) that is functionally lowered to
if (structure of object == the structure of the object when the loop started)
property_value = object->properties[current_index++]
else
property_value = object[property_name_list[current_index++]
where property_name_list
is the list of all the properties to visit, in the order to be visited, that is cached on the object structureid (JSC terminology for a “hidden class”), so it’s ideally calculated once.