Performance reegression: for..in loops in node 8+ grow superlinearly with object size (even if returning after 1 iteration) #20463
Labels
invalid
Issues and PRs that are invalid.
performance
Issues and PRs related to the performance of Node.js.
regression
Issues related to regressions.
v8 engine
Issues and PRs related to the V8 dependency.
The following benchmark tests a
for...in
loop that returns after a single iteration.Since the loop returns after only one iteration, naively I'd have thought it would be either constant-time with object size, at least sublinear.
In practice it seems to grow either linearly or superlinearly with object size, depending on node version. E.g. for objects between 10k and 30k properties, node 7 is approx linear, node 8 is both much slower generally and also superlinear:
node 7:
node 8:
Node 10 behaves similarly.
(Side note: Node 7 has its own issues, but rather than superlinear growth at past a certain point, it has a sharp discontinuity at around 50.8k:
and similarly for node 6 but with the discontinuity at a different point)
I realise the practical solution is 'just use
Map
orSet
if you want constant-time isEmpty using.size
for large n', and sure, that's what we'll do. But even so, the behaviour in node 8+ compared to 7 and below is clearly a regression, so thought I'd flag it up.The text was updated successfully, but these errors were encountered: