From 07ef0d6253e29d50c5b25714feb6dbe8a7b53c8d Mon Sep 17 00:00:00 2001 From: Carlo Alberto Ferraris Date: Fri, 14 Aug 2015 11:36:50 +0900 Subject: [PATCH] Optimize PriorityQueue.js update shows up as the hottest function in the chrome profiler. Avoid pointlessly serializing over-and-over the same values: this also helps the JIT because the shape of the objects does not change as often. --- lib/riemann/dash/public/vendor/PriorityQueue.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/riemann/dash/public/vendor/PriorityQueue.js b/lib/riemann/dash/public/vendor/PriorityQueue.js index 7d31b69..492cbe8 100644 --- a/lib/riemann/dash/public/vendor/PriorityQueue.js +++ b/lib/riemann/dash/public/vendor/PriorityQueue.js @@ -7,8 +7,9 @@ * @author Augusto Pascutti */ var QueueItem = function(v, p) { - this.value = v; - this.priority = p; + this.value = v; + this.priority = p; + this.value_JSON = JSON.stringify(v); }; /** @@ -64,8 +65,9 @@ PriorityQueue.prototype = { known = false; idx = 0; + var value_JSON = JSON.stringify(value); this._queue.forEach(function() { - if (JSON.stringify(this._queue[idx].value) === JSON.stringify(value)) { + if (this._queue[idx].value_JSON === value_JSON) { this._queue[idx].priority = priority; known = true; return;