Skip to content
Permalink
Browse files
[WTF] Use quadratic-probing instead of double-hashing
https://bugs.webkit.org/show_bug.cgi?id=239813

Reviewed by Geoffrey Garen.

If table size is always power-of-two, we can safely use quadratic-probing[1] even if the load exceeds 50%.
Quadratic-probing and double-hashing have different tradeoff between clustering possibility and CPU cache
friendliness. Double-hashing can avoid clustering more, but it is not CPU cache friendly. Quadratic-probing
can cause clustering more but better for CPU cache. And while linear-probing caused a lot of trouble and not
practical, quadratic-probing with 75% load factor is practical configuration which is used in production-ready
hashtables e.g. Google's sparsetable / densetable[2].

This patch replaces WTF::HashTable's probing algorithm from double-hashing to quadratic-probing to make it more
cache friendly while keeping reasonable clustering characteristics (compared to linear-probing etc.). Due to
this cache friendliness, we get large performance improvements.

1. 0.52% improvement in Speedometer2 with 95% probability.
2. 0.72% improvement in JetStream2 with 98% probability.

[1]: https://fgiesen.wordpress.com/2015/02/22/triangular-numbers-mod-2n/
[2]: http://goog-sparsehash.sourceforge.net/doc/implementation.html

Canonical link: https://commits.webkit.org/250093@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293579 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Constellation committed Apr 28, 2022
1 parent 20c42f5 commit 28e2c3d6e886089048ec5750e15bc1a9db079977
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 68 deletions.
@@ -1,3 +1,19 @@
2022-04-28 Yusuke Suzuki <ysuzuki@apple.com>

[WTF] Use quadratic-probing instead of double-hashing
https://bugs.webkit.org/show_bug.cgi?id=239813

Reviewed by Geoffrey Garen.

The following tests are relying on HashTable's ordering which is not guaranteed.

* media/media-session/actionHandlerInternalMappings-expected.txt:
* platform/glib/accessibility/content-editable-as-textarea-expected.txt:
* platform/gtk/accessibility/native-text-control-attributed-string-expected.txt:
* storage/indexeddb/getdatabases-expected.txt:
* storage/indexeddb/getdatabases-private-expected.txt:
* storage/indexeddb/resources/getdatabases.js:

2022-04-28 Antti Koivisto <antti@apple.com>

[ iOS ] tables/mozilla/bugs/bug26178.html is a constant failure
@@ -22,12 +22,12 @@ ACTION: seekto
Command: SeekToPlaybackPositionCommand
Iterate over all possible actions
Command: PauseCommand
Command: PlayCommand
Command: SkipBackwardCommand
Command: SkipForwardCommand
Command: NextTrackCommand
Command: PreviousTrackCommand
Command: SeekToPlaybackPositionCommand
Command: PlayCommand
Command: PreviousTrackCommand
Command: NextTrackCommand
Command: StopCommand
Iterate over possible actions after video element src is cleared
RUN(video.src = "")
@@ -15,13 +15,13 @@ Attributed string with range:
family-name:-webkit-standard
editable:true
strikethrough:false
direction:ltr
style:normal
fg-color:0,0,0
size:12pt
weight:400
size:12pt
invisible:false
underline:none
direction:ltr
Range attributes for 'ello<\n>':
Range attributes for 'worl':
weight:700
@@ -10,13 +10,13 @@ Attributed string for range (0, 9):
bg-color:255,255,255
editable:true
strikethrough:false
direction:ltr
style:normal
weight:400
fg-color:0,0,0
size:12pt
weight:400
invisible:false
underline:none
direction:ltr
Range attributes for 'some word':
Attributed string for range (0, 3):
Default text attributes:
@@ -25,13 +25,13 @@ Attributed string for range (0, 3):
bg-color:255,255,255
editable:true
strikethrough:false
direction:ltr
style:normal
weight:400
fg-color:0,0,0
size:12pt
weight:400
invisible:false
underline:none
direction:ltr
Range attributes for 'som':
Attributed string for range (5, 4):
Default text attributes:
@@ -40,13 +40,13 @@ Attributed string for range (5, 4):
bg-color:255,255,255
editable:true
strikethrough:false
direction:ltr
style:normal
weight:400
fg-color:0,0,0
size:12pt
weight:400
invisible:false
underline:none
direction:ltr
Range attributes for 'word':
Attributed string for range (5, 10):
Attributed string for range (10, 1):
@@ -57,13 +57,13 @@ Attributed string for range (-1, 1):
bg-color:255,255,255
editable:true
strikethrough:false
direction:ltr
style:normal
weight:400
fg-color:0,0,0
size:12pt
weight:400
invisible:false
underline:none
direction:ltr
Range attributes for 's':

Attributed string for range (0, 3):
@@ -73,13 +73,13 @@ Attributed string for range (0, 3):
bg-color:255,255,255
editable:true
strikethrough:false
direction:ltr
style:normal
weight:400
fg-color:0,0,0
size:12pt
weight:400
invisible:false
underline:none
direction:ltr
Range attributes for '•••':
Attributed string for range (0, 2):
Default text attributes:
@@ -88,13 +88,13 @@ Attributed string for range (0, 2):
bg-color:255,255,255
editable:true
strikethrough:false
direction:ltr
style:normal
weight:400
fg-color:0,0,0
size:12pt
weight:400
invisible:false
underline:none
direction:ltr
Range attributes for '••':
Attributed string for range (1, 2):
Default text attributes:
@@ -103,13 +103,13 @@ Attributed string for range (1, 2):
bg-color:255,255,255
editable:true
strikethrough:false
direction:ltr
style:normal
weight:400
fg-color:0,0,0
size:12pt
weight:400
invisible:false
underline:none
direction:ltr
Range attributes for '••':
Attributed string for range (1, 10):
Attributed string for range (10, 1):
@@ -120,13 +120,13 @@ Attributed string for range (-1, 1):
bg-color:255,255,255
editable:true
strikethrough:false
direction:ltr
style:normal
weight:400
fg-color:0,0,0
size:12pt
weight:400
invisible:false
underline:none
direction:ltr
Range attributes for '•':

PASS successfullyParsed is true
@@ -10,8 +10,8 @@ PASS databases.length is 1
PASS databases[0].version is 1
PASS databases[0].name is "getdatabase-first"
PASS databases.length is 2
PASS databases[1].version is 2
PASS databases[1].name is "getdatabase-second"
PASS databases[0].version is 2
PASS databases[0].name is "getdatabase-second"
PASS successfullyParsed is true

TEST COMPLETE
@@ -10,8 +10,8 @@ PASS databases.length is 1
PASS databases[0].version is 1
PASS databases[0].name is "getdatabase-first"
PASS databases.length is 2
PASS databases[1].version is 2
PASS databases[1].name is "getdatabase-second"
PASS databases[0].version is 2
PASS databases[0].name is "getdatabase-second"
PASS successfullyParsed is true

TEST COMPLETE
@@ -35,8 +35,8 @@ function continueTest() {
indexedDB.databases().then((result) => {
databases = result;
shouldBeEqualToNumber("databases.length", 2);
shouldBeEqualToNumber("databases[1].version", 2);
shouldBeEqualToString("databases[1].name", "getdatabase-second");
shouldBeEqualToNumber("databases[0].version", 2);
shouldBeEqualToString("databases[0].name", "getdatabase-second");
finishJSTest();
});
}
@@ -1,3 +1,35 @@
2022-04-28 Yusuke Suzuki <ysuzuki@apple.com>

[WTF] Use quadratic-probing instead of double-hashing
https://bugs.webkit.org/show_bug.cgi?id=239813

Reviewed by Geoffrey Garen.

If table size is always power-of-two, we can safely use quadratic-probing[1] even if the load exceeds 50%.
Quadratic-probing and double-hashing have different tradeoff between clustering possibility and CPU cache
friendliness. Double-hashing can avoid clustering more, but it is not CPU cache friendly. Quadratic-probing
can cause clustering more but better for CPU cache. And while linear-probing caused a lot of trouble and not
practical, quadratic-probing with 75% load factor is practical configuration which is used in production-ready
hashtables e.g. Google's sparsetable / densetable[2].

This patch replaces WTF::HashTable's probing algorithm from double-hashing to quadratic-probing to make it more
cache friendly while keeping reasonable clustering characteristics (compared to linear-probing etc.). Due to
this cache friendliness, we get large performance improvements.

1. 0.52% improvement in Speedometer2 with 95% probability.
2. 0.72% improvement in JetStream2 with 98% probability.

[1]: https://fgiesen.wordpress.com/2015/02/22/triangular-numbers-mod-2n/
[2]: http://goog-sparsehash.sourceforge.net/doc/implementation.html

* wtf/HashTable.h:
(WTF::KeyTraits>::inlineLookup):
(WTF::KeyTraits>::lookupForWriting):
(WTF::KeyTraits>::fullLookupForWriting):
(WTF::KeyTraits>::addUniqueForInitialization):
(WTF::KeyTraits>::add):
(WTF::doubleHash): Deleted.

2022-04-28 Per Arne Vollan <pvollan@apple.com>

[iOS] Enable IOKit blocking in GPUP by default

0 comments on commit 28e2c3d

Please sign in to comment.