Off the top of my head, the advantages of mozilla::Hash{Map,Set} over std::unordered_{map,set} are the following.
- They are much faster on Mac and Linux and not much different on Windows: https://treeherder.mozilla.org/perf.html#/graphs?timerange=604800&series= mozilla-central,1732084,1,6&series=mozilla-central, 1730153,1,6&series=mozilla-central,1732083,1,6&series= mozilla-central,1730147,1,6&series=mozilla-central, 1732092,1,6&series=mozilla-central,1730159,1,6 - The code is the same on all platforms, so there's no performance variation. - They integrate well with Mozilla code, e.g. by using AllocPolicy. - They support memory reporting, via the shallowSizeOf{In,Ex}cluding() methods. - They don't use exceptions. (I'm not sure if std::unordered_{map,set} use exceptions.) - Generated code size is similar on Linux64; I haven't tried other platforms. (PLDHash is substantially smaller, by comparison.) Nick On Thu, Aug 16, 2018 at 6:18 AM, Jeff Gilbert <jgilb...@mozilla.com> wrote: > Awesome! > > What are the pros/cons to mozilla::Hash{Map,Set} vs > std::unordered_{map,set}? I'm assuming perf is the main draw? Do we > have a data on this too? > > On Mon, Aug 13, 2018 at 10:44 PM, Nicholas Nethercote > <n.netherc...@gmail.com> wrote: > > Hi, > > > > I recently moved Spidermonkey's js::Hash{Map,Set} classes from > > js/public/HashTable.h into mfbt/HashTable.h and renamed them as > > mozilla::Hash{Map,Set}. They can now be used throughout Gecko. > > > > (js/public/HashTable.h still exists in order to provide renamings of > > mozilla::Hash{Map,Set} as js::Hash{Map,Set}.) > > > > Why might you use mozilla::Hash{Map,Set} instead of PLDHashTable (or > > nsTHashtable and other descendants)? > > > > - Better API: these types provide proper HashMap and HashSet instances, > and > > (in my opinion) are easier to use. > > > > - Speed: the microbenchmark in xpcom/rust/gtest/bench-collect > ions/Bench.cpp > > shows that mozilla::HashSet is 2x or more faster than PLDHashTable. E.g. > > compare "MozHash" against "PLDHash" in this graph: > > > > https://treeherder.mozilla.org/perf.html#/graphs?timerange= > 604800&series=mozilla-central,1730159,1,6&series=mozilla- > central,1730162,1,6&series=mozilla-central,1730164,1,6& > series=mozilla-central,1732092,1,6&series=mozilla- > central,1730163,1,6&series=mozilla-central,1730160,1,6 > > > > Bug 1477627 converted a hot hash table from PLDHashTable to > > mozilla::HashSet and appears to have sped up cycle collection in some > cases > > by 7%. If you know of another PLDHashTable that is hot, it might be worth > > converting it to mozilla::HashTable. > > > > Both mozilla::Hash{Map,Set} and PLDHashTable use the same double-hashing > > algorithm; the speed difference is due to mozilla::HashSet's extensive > use > > of templating and inlining. The downside of this is that mozilla::HashSet > > will increase binary size more than PLDHashTable. > > > > There are overview comments at the top of mfbt/HashTable.h, and the > classes > > themselves have more detailed comments about every method. > > > > Nick > > _______________________________________________ > > dev-platform mailing list > > dev-platform@lists.mozilla.org > > https://lists.mozilla.org/listinfo/dev-platform > _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform