Improve bot watcher's dashboard performance
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Feb 2017 19:11:27 +0000 (19:11 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Feb 2017 19:11:27 +0000 (19:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=168624
<rdar://problem/30190109>

Reviewed by Daniel Bates.

* BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Trac.js:
There was an unnecessary linear complexity algorithm in indexOfRevision().

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@212729 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Trac.js
Tools/ChangeLog

index 37b3241..bf056b5 100644 (file)
@@ -37,6 +37,7 @@ Trac = function(baseURL, options)
     }
 
     this.recordedCommits = []; // Will be sorted in ascending order.
+    this.recordedCommitIndicesByRevisionNumber = {};
 };
 
 BaseObject.addConstructorFunctions(Trac);
@@ -223,11 +224,6 @@ Trac.prototype = {
         if (!dataDocument)
             return;
 
-        var recordedRevisionNumbers = this.recordedCommits.reduce(function(previousResult, commit) {
-            previousResult[commit.revisionNumber] = commit;
-            return previousResult;
-        }, {});
-
         var knownCommitsWereUpdated = false;
         var newCommits = [];
 
@@ -235,19 +231,25 @@ Trac.prototype = {
         var commitInfoElement;
         while (commitInfoElement = commitInfoElements.iterateNext()) {
             var commit = this._convertCommitInfoElementToObject(dataDocument, commitInfoElement);
-            if (commit.revisionNumber in recordedRevisionNumbers) {
+            var knownCommitIndex = this.recordedCommitIndicesByRevisionNumber[commit.revisionNumber];
+            if (knownCommitIndex >= 0) {
                 // Author could have changed, as commit queue replaces it after the fact.
-                console.assert(recordedRevisionNumbers[commit.revisionNumber].revisionNumber === commit.revisionNumber);
-                if (recordedRevisionNumbers[commit.revisionNumber].author != commit.author) {
-                    recordedRevisionNumbers[commit.revisionNumber].author = commit.author;
+                console.assert(this.recordedCommits[knownCommitIndex].revisionNumber === commit.revisionNumber);
+                if (this.recordedCommits[knownCommitIndex].author != commit.author) {
+                    this.recordedCommits[knownCommitIndex].author = commit.author;
                     knownCommitWasUpdated = true;
                 }
             } else
                 newCommits.push(commit);
         }
 
-        if (newCommits.length)
+        if (newCommits.length) {
             this.recordedCommits = newCommits.concat(this.recordedCommits).sort(function(a, b) { return a.date - b.date; });
+            this.recordedCommitIndicesByRevisionNumber = {};
+            this.recordedCommits.forEach(function(curentValue, index) {
+                this.recordedCommitIndicesByRevisionNumber[curentValue.revisionNumber] = index;
+            }, this);
+        }
 
         if (newCommits.length || knownCommitsWereUpdated)
             this.dispatchEventToListeners(Trac.Event.CommitsUpdated, null);
@@ -318,13 +320,12 @@ Trac.prototype = {
         return Trac.NO_MORE_REVISIONS;
     },
 
-    indexOfRevision: function(revision)
+    indexOfRevision: function(revisionNumber)
     {
-        var commits = this.recordedCommits;
-        for (var i = 0; i < commits.length; ++i) {
-            if (commits[i].revisionNumber === revision)
-                return i;
-        }
-        return -1;
+        var result = this.recordedCommitIndicesByRevisionNumber[revisionNumber];
+        // FIXME: Update callers to handle undefined result.
+        if (result === undefined)
+            return -1;
+        return result;
     },
 };
index 8b5ea49..c9219f7 100644 (file)
@@ -1,3 +1,14 @@
+2017-02-21  Alexey Proskuryakov  <ap@apple.com>
+
+        Improve bot watcher's dashboard performance
+        https://bugs.webkit.org/show_bug.cgi?id=168624
+        <rdar://problem/30190109>
+
+        Reviewed by Daniel Bates.
+
+        * BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Trac.js:
+        There was an unnecessary linear complexity algorithm in indexOfRevision().
+
 2017-02-21  Alex Christensen  <achristensen@webkit.org>
 
         Unreviewed, rolling out r212699.