Skip to content

Commit

Permalink
fix: performance bottleneck in stat.js (#463)
Browse files Browse the repository at this point in the history
Array.shift seems to be very slow, perhaps linear, on some
engines, resulting in  _update consuming a lot of CPU.
  • Loading branch information
betamos authored and jacobheun committed Oct 14, 2019
1 parent 35aa45c commit 93a1e42
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/switch/stats/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ class Stats extends EventEmitter {
this._timeout = null
if (this._queue.length) {
let last
while (this._queue.length) {
const op = last = this._queue.shift()
this._applyOp(op)
for (last of this._queue) {
this._applyOp(last)
}
this._queue = []

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

Expand Down

0 comments on commit 93a1e42

Please sign in to comment.