Chromium Code Reviews
DescriptionSpeed up object-keyed Map and Set by giving out sequential hash codes.
The previous code generated random hash codes for JS objects. These codes
are not visible to JS, but are used by the implementation of Set() and Map().
An open addressed hash table is very sensitive to sequential hash codes,
because they "block off" areas of the hash table, and this means that when
you get a collision in the table, you get a lot of collisions, as the default simple
search for a free slot steps through the blocked off area.
However the implementation in Set() and Map() is not sensitive to sequences
of sequential hash codes. In fact they work really well and collisions are rare and harmless. In particular, for large tables, the cache behaviour is much better both on insertion and rehashing (pauses).
For the example given in https://code.google.com/p/v8/issues/detail?id=4086 V8 runs very badly unless you give it enough memory with a flag. If you give it enough memory then it still isn't very fast. This patch cuts 40% off the run time of the Map() section of the test.
On that bug there is a suggestion by me to give newly created objects a hash code immediately, which also cuts the running time of the Map() section of the test by 40%. These are not the same 40%, though, because combining the two changes reduces running time by 77%, ie a 4x speedup.
R=adamk@chromium.org, verwaest@chromium.org
BUG=v8:4086
LOG=n
Patch Set 1 #Patch Set 2 : Revert inadvertent change #
Messages
Total messages: 4 (0 generated)
|
||||||||||||||||||||||||||||