Bug 1527238 - Speed up webconsole server's autocomplete function; r=Honza.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Fri, 15 Feb 2019 15:02:51 +0000
changeset 459547 a2bc2cdbcea34ff5e6a5d0576bc36ad5eede0550
parent 459546 8ced3fcdd37c8746935916eb5e746c0ebde84a75
child 459550 45aaded7cf63b11145f86083e08aca4a21710cff
child 459580 ed60c55e6f005b5a382606ec1d4fbc71fd5272c6
push id111964
push usercsabou@mozilla.com
push dateFri, 15 Feb 2019 18:54:44 +0000
treeherdermozilla-inbound@db3c4f905082 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1527238
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1527238 - Speed up webconsole server's autocomplete function; r=Honza. There are 2 changes in this patch. In js-property-provider, we iterate over a Set and delete item we don't want into instead of turning the Set into an array, filter on it, and convert it back to a new Set. In the autocomplete function, we don't use regexp anymore in the sort callback as we already have a way to tell if we're performing an element access. Differential Revision: https://phabricator.services.mozilla.com/D19471
devtools/server/actors/webconsole.js
devtools/shared/webconsole/js-property-provider.js
--- a/devtools/server/actors/webconsole.js
+++ b/devtools/server/actors/webconsole.js
@@ -1237,21 +1237,21 @@ WebConsoleActor.prototype =
           if (keyword.startsWith(result.matchProp)) {
             matches.add(keyword);
           }
         }
       }
 
       // Sort the results in order to display lowercased item first (e.g. we want to
       // display `document` then `Document` as we loosely match the user input if the
-      // first letter they typed was lowercase).
+      // first letter was lowercase).
+      const firstMeaningfulCharIndex = isElementAccess ? 1 : 0;
       matches = Array.from(matches).sort((a, b) => {
-        const startingQuoteRegex = /^('|"|`)/;
-        const aFirstMeaningfulChar = startingQuoteRegex.test(a) ? a[1] : a[0];
-        const bFirstMeaningfulChar = startingQuoteRegex.test(b) ? b[1] : b[0];
+        const aFirstMeaningfulChar = a[firstMeaningfulCharIndex];
+        const bFirstMeaningfulChar = b[firstMeaningfulCharIndex];
         const lA = aFirstMeaningfulChar.toLocaleLowerCase() === aFirstMeaningfulChar;
         const lB = bFirstMeaningfulChar.toLocaleLowerCase() === bFirstMeaningfulChar;
         if (lA === lB) {
           return a < b ? -1 : 1;
         }
         return lA ? -1 : 1;
       });
     }
--- a/devtools/shared/webconsole/js-property-provider.js
+++ b/devtools/shared/webconsole/js-property-provider.js
@@ -479,28 +479,26 @@ function JSPropertyProvider({
     if (isElementAccess) {
       // If it's an element access, we need to wrap properties in quotes (either the one
       // the user already typed, or `"`).
       matches = wrapMatchesInQuotes(matches, elementAccessQuote);
     } else if (!isWorker) {
       // If we're not performing an element access, we need to check that the property
       // are suited for a dot access. (Reflect.jsm is not available in worker context yet,
       // see Bug 1507181).
-      matches = new Set([...matches].filter(propertyName => {
-        let valid = true;
+      for (const match of matches) {
         try {
           // In order to know if the property is suited for dot notation, we use Reflect
           // to parse an expression where we try to access the property with a dot. If it
           // throws, this means that we need to do an element access instead.
-          Reflect.parse(`({${propertyName}: true})`);
+          Reflect.parse(`({${match}: true})`);
         } catch (e) {
-          valid = false;
+          matches.delete(match);
         }
-        return valid;
-      }));
+      }
     }
 
     return {isElementAccess, matchProp, matches};
   };
 
   // If the final property is a primitive
   if (typeof obj != "object") {
     return prepareReturnedObject(getMatchedProps(obj, search));