This spun out from exploring isaacs/node-lru-cache#54
It may very well be a v8 issue, but I haven't been able to find the right circumstances to reproduce due to v8's lack of setImmediate
When running the following program in 4.x (on Linux or Mac), there's a huge slowdown around iteration 92000 that does not occur in 3.x or below:
varlruCache=Object.create(null)vari=0varlast=Date.now()varmax=4097// lowering to 4096 fixes the problemfunctionnext(){lruCache[i]=trueif(i>=max)deletelruCache[i-max]i++if(i>200000)returnif((i%2000)===0){varnow=Date.now()console.log({duration: now-last,iteration: i,})last=now}setImmediate(next)}next()So in 4.x the output looks like:
$ node test.js{ duration: 6, iteration: 2000 }{ duration: 22, iteration: 4000 }{ duration: 6, iteration: 6000 }{ duration: 4, iteration: 8000 }{ duration: 3, iteration: 10000 }...{ duration: 5, iteration: 90000 }{ duration: 3, iteration: 92000 }{ duration: 4870, iteration: 94000 }{ duration: 5151, iteration: 96000 }{ duration: 5336, iteration: 98000 }{ duration: 782, iteration: 100000 }{ duration: 7, iteration: 102000 }{ duration: 5, iteration: 104000 }...{ duration: 8, iteration: 200000 }Using 3.3.1 or lowering max to 4096 looks like:
{ duration: 7, iteration: 2000 }{ duration: 18, iteration: 4000 }{ duration: 9, iteration: 6000 }...{ duration: 7, iteration: 90000 }{ duration: 6, iteration: 92000 }{ duration: 6, iteration: 94000 }{ duration: 7, iteration: 96000 }...{ duration: 5, iteration: 198000 }{ duration: 9, iteration: 200000 }I'm 85% sure this is the same issue, or at least very similar to the one that's exhibited in isaacs/node-lru-cache#54 – just as a more refined reproduction. The main difference is in the lru-cache issue it doesn't seem to ever speed up again (some sort of reoptimization?).
This spun out from exploring isaacs/node-lru-cache#54
It may very well be a v8 issue, but I haven't been able to find the right circumstances to reproduce due to v8's lack of
setImmediateWhen running the following program in 4.x (on Linux or Mac), there's a huge slowdown around iteration 92000 that does not occur in 3.x or below:
So in 4.x the output looks like:
Using 3.3.1 or lowering
maxto 4096 looks like:I'm 85% sure this is the same issue, or at least very similar to the one that's exhibited in isaacs/node-lru-cache#54 – just as a more refined reproduction. The main difference is in the lru-cache issue it doesn't seem to ever speed up again (some sort of reoptimization?).