Skip to content

Commit 93a1e42

Browse files
betamosjacobheun
authored andcommitted
fix: performance bottleneck in stat.js (#463)
Array.shift seems to be very slow, perhaps linear, on some engines, resulting in _update consuming a lot of CPU.
1 parent 35aa45c commit 93a1e42

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/switch/stats/stat.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ class Stats extends EventEmitter {
139139
this._timeout = null
140140
if (this._queue.length) {
141141
let last
142-
while (this._queue.length) {
143-
const op = last = this._queue.shift()
144-
this._applyOp(op)
142+
for (last of this._queue) {
143+
this._applyOp(last)
145144
}
145+
this._queue = []
146146

147147
this._updateFrequency(last[2]) // contains timestamp of last op
148148

0 commit comments

Comments
 (0)