Bug 1257207 - Increase ATOM_HASHTABLE_INITIAL_LENGTH. r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 24 Mar 2016 09:17:55 +1100
changeset 290181 c617aafb0e961fb863d3a5222dbca082a6a9c3b5
parent 290180 4400a8b6aaeb9abadb250bdb49452275884540dd
child 290182 0eba208813c315fac76f9825cb1385c7432c1f44
push id30114
push usercbook@mozilla.com
push dateThu, 24 Mar 2016 15:15:54 +0000
treeherdermozilla-central@24c5fbde4488 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1257207
milestone48.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 1257207 - Increase ATOM_HASHTABLE_INITIAL_LENGTH. r=froydnj. This avoids one gAtomTable resizing.
xpcom/ds/nsAtomTable.cpp
--- a/xpcom/ds/nsAtomTable.cpp
+++ b/xpcom/ds/nsAtomTable.cpp
@@ -517,17 +517,28 @@ NS_SizeOfAtomTablesIncludingThis(MallocS
 
   // The atoms in the this table are almost certainly stored in static data, so
   // we don't need to measure entries separately.
   *aStatic = gStaticAtomTable
            ? gStaticAtomTable->ShallowSizeOfIncludingThis(aMallocSizeOf)
            : 0;
 }
 
-#define ATOM_HASHTABLE_INITIAL_LENGTH  2048
+// The atom table very quickly gets 10,000+ entries in it (or even 100,000+).
+// But choosing the best initial length has some subtleties: we add ~2700
+// static atoms to the table at start-up, and then we start adding and removing
+// dynamic atoms. If we make the table too big to start with, when the first
+// dynamic atom gets removed the load factor will be < 25% and so we will
+// shrink it to 4096 entries.
+//
+// By choosing an initial length of 4096, we get an initial capacity of 8192.
+// That's the biggest initial capacity that will let us be > 25% full when the
+// first dynamic atom is removed (when the count is ~2700), thus avoiding any
+// shrinking.
+#define ATOM_HASHTABLE_INITIAL_LENGTH  4096
 
 static inline void
 EnsureTableExists()
 {
   if (!gAtomTable) {
     gAtomTable = new PLDHashTable(&AtomTableOps, sizeof(AtomTableEntry),
                                   ATOM_HASHTABLE_INITIAL_LENGTH);
   }