1
0
forked from 0ad/0ad

Speed up timer update by using Map.forEach

According to JIT profiling on SM 115, using ForEach is faster than
iterating.
This is a micro optimisation, maybe 2% faster for OnUpdate, which means
we might see an overall improvement < 0.4%.

The reason this is faster here is that Iterating needs to construct an
array to store the result, whereas ForEach just uses the values
directly. This means this probably doesn't apply to iterating if we
don't need both the key/value pair.

Differential Revision: https://code.wildfiregames.com/D5010
This was SVN commit r27674.
This commit is contained in:
wraitii 2023-06-13 15:57:18 +00:00
parent 7350b9042e
commit 3991c5c857

View File

@ -114,9 +114,10 @@ Timer.prototype.OnUpdate = function(msg)
// (We do this in two stages to avoid deleting from the timer list while
// we're in the middle of iterating through it)
let run = [];
for (let [id, timer] of this.timers)
this.timers.forEach((timer, id) => {
if (timer.time <= this.time)
run.push(id);
});
for (let id of run)
{