Bug 1402944: Part 11 - Use number rather than string value for getUniqueId(). r?mixedpuppy draft
authorKris Maglione <maglione.k@gmail.com>
Mon, 25 Sep 2017 15:00:17 -0700
changeset 670810 a5c69dc96f3330a3b78bf8161b83c88eff176608
parent 670809 b91f2c7f93fcc7b8ff0ed123b3513d8cc181cc67
child 733312 fd4b32d9c6cffe97ca77f668f205d99d783348b3
push id81714
push usermaglione.k@gmail.com
push dateTue, 26 Sep 2017 21:30:45 +0000
reviewersmixedpuppy
bugs1402944
milestone58.0a1
Bug 1402944: Part 11 - Use number rather than string value for getUniqueId(). r?mixedpuppy This allows us to avoid a fairly expensive stringification/string allocation when calling getUniqueId(), which is helpful. It also allows us to avoid atomizing the ID string when storing it in a Set or Map, which is even more helpful. And, of course, it makes comparisons faster. MozReview-Commit-ID: 8wMc6TdhzfY
toolkit/components/extensions/ExtensionUtils.jsm
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -23,20 +23,25 @@ function getConsole() {
   });
 }
 
 XPCOMUtils.defineLazyGetter(this, "console", getConsole);
 
 const appinfo = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
 
 let nextId = 0;
-const uniqueProcessID = String(appinfo.uniqueProcessID);
+const uniqueProcessID = appinfo.uniqueProcessID;
+// Store the process ID in a 16 bit field left shifted to end of a
+// double's mantissa.
+const processIDMask = uniqueProcessID * (2 ** 37);
 
 function getUniqueId() {
-  return `${nextId++}-${uniqueProcessID}`;
+  // Note: We can't use bitwise ops here, since they truncate to a 32 bit
+  // integer and we need all 52 mantissa bits.
+  return processIDMask + nextId++;
 }
 
 
 /**
  * An Error subclass for which complete error messages are always passed
  * to extensions, rather than being interpreted as an unknown error.
  */
 class ExtensionError extends Error {}