Repository navigation
Commit 53bedf6
committed
Store one status byte per bucket in WTF::HashTable
https://bugs.webkit.org/show_bug.cgi?id=330025
rdar://191722665
Reviewed by Yusuke Suzuki.
The status byte stores empty, deleted, or 7 bits of the key's hash. (And we use
additional hash bits, scaled with table size, to index into the status byte
array.)
This eliminates the need for special empty / deleted keys per type, which have
been a common source of bugs.
(RobinHoodHashTable still uses special empty / deleted keys, so it needs a
follow-up before we can remove them entirely.)
This is also a speedup:
0.94%, 1.36% Speedometer 3
0.47% MotionMark
0.39%, 0.79% JetStream 3.0
Likely sources of speedup:
* Misses and collisions are faster because, on average, ~95% of lookups
terminate in a single cache line without any extra key comparisons.
* Iteration during rehash and destruction are faster because we touch less
memory, especially for sparse tables.
Note: I also benchmarked popular "Swiss" / SIMD hash tables. They were slower.
The likely explanation is fixed costs from extra bit twiddling and SIMD latency,
especially in small tables, which are common in WebKit.
(SIMD benchmarked faster for very large tables with very high load factors. So
SIMD might be a path to memory savings in the future.)
I had to fix hash translators that assigned their keys instead of constructing
them. Assigning was always sketchy in theory (since the assigned-to location was
the sentinel empty / deleted key, which is not valid to access in any way), but
it is now much more likely to encounter truly uninitialized bits in practice.
(Perhaps a follow-up should pass void* or span<char> to translators, to prevent
this mistake at compile time.)
Tests: Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp
Tools/TestWebKitAPI/Tests/WTF/HashSet.cpp
Tools/TestWebKitAPI/Tests/WTF/HashTable.cpp
* Source/JavaScriptCore/dfg/DFGCSEPhase.cpp:
* Source/JavaScriptCore/dfg/DFGLazyJSValue.cpp:
(JSC::DFG::CrossThreadStringTranslator::translate):
* Source/JavaScriptCore/jit/JITThunks.cpp:
(JSC::JITThunks::NativeExecutableTranslator::translate):
* Source/WTF/wtf/Compiler.h: Add ALWAYS_INLINE_CALLEE.
* Source/WTF/wtf/HashMap.h:
(WTF::HashMapTranslator::translate):
(WTF::HashMapTranslatorAdapter::translate):
* Source/WTF/wtf/HashSet.h:
(WTF::HashSetTranslator::translate):
(WTF::HashSetTranslatorAdapter::translate):
(WTF::HashSetEnsureTranslatorAdaptor::translate):
(WTF::shouldValidateKey>::take): Fix hash translators that assigned instead of
constructing.
* Source/WTF/wtf/HashTable.h: New implementation, including status bytes.
* Source/WTF/wtf/ListHashSet.h:
(WTF::ListHashSetTranslator::translate): More hash translator fixes.
* Source/WTF/wtf/RobinHoodHashTable.h: Copied the old iterators into
RobinHoodHashTable since HashTable iterates differently now.
* Source/WTF/wtf/SmallMap.h: Remove isValidKey() assertions because all keys
are valid now.
* Source/WTF/wtf/text/AtomStringImpl.cpp:
(WTF::UTF16BufferTranslator::translate):
(WTF::SubstringTranslator::translate):
(WTF::Latin1BufferTranslator::translate):
(WTF::BufferFromStaticDataTranslator::translate):
(WTF::StaticStringAtomTranslator::translate):
* Source/WTF/wtf/text/StringHash.h:
(WTF::StringViewHashTranslator::translate):
(WTF::ASCIICaseInsensitiveStringViewHashTranslator::translate):
(WTF::HashTranslatorASCIILiteral::translate):
* Source/WebCore/contentextensions/CombinedFiltersAlphabet.cpp:
(WebCore::ContentExtensions::TermCreatorTranslator::translate):
* Source/WebCore/contentextensions/NFAToDFA.cpp:
(WebCore::ContentExtensions::NodeIdSetToUniqueNodeIdSetTranslator::translate):
* Source/WebCore/dom/DocumentSharedObjectPool.cpp:
(WebCore::AttributeSpanTranslator::translate):
* Source/WebCore/dom/QualifiedNameCache.cpp:
(WebCore::QNameComponentsTranslator::translate):
* Source/WebCore/platform/graphics/cg/CGSubimageCacheWithTimer.cpp:
(WebCore::CGSubimageCacheAdder::translate):
* Source/WebCore/rendering/TextAutoSizing.cpp:
(WebCore::TextAutoSizingHashTranslator::translate): More hash translator fixes.
* Tools/Scripts/webkitpy/api_tests/allowlist.txt: Removed tests we don't need anymore.
* Tools/TestWebKitAPI/CMakeLists.txt:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added HashTable.cpp.
* Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp:
* Tools/TestWebKitAPI/Tests/WTF/HashSet.cpp: Removed empty / deleted tests
because that bug can't happen anymore.
* Tools/TestWebKitAPI/Tests/WTF/HashTable.cpp: Asked claude to go nuts on
regression tests for new edge cases.
Canonical link: https://commits.webkit.org/325806@main1 parent f79d4db commit 53bedf6
25 files changed
Lines changed: 1728 additions & 594 deletions
File tree
- Source
- JavaScriptCore
- dfg
- jit
- WTF/wtf
- text
- WebCore
- contentextensions
- dom
- platform/graphics/cg
- rendering
- Tools
- Scripts/webkitpy/api_tests
- TestWebKitAPI
- TestWebKitAPI.xcodeproj
- Tests/WTF
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
| 121 | + | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
291 | | - | |
| 291 | + | |
292 | 292 | | |
293 | | - | |
| 293 | + | |
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
216 | 227 | | |
217 | 228 | | |
218 | 229 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
272 | | - | |
| 272 | + | |
273 | 273 | | |
274 | | - | |
275 | | - | |
| 274 | + | |
| 275 | + | |
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
283 | | - | |
| 283 | + | |
284 | 284 | | |
285 | | - | |
286 | | - | |
| 285 | + | |
| 286 | + | |
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | | - | |
240 | | - | |
241 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
| 249 | + | |
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | | - | |
| 259 | + | |
260 | 260 | | |
261 | | - | |
| 261 | + | |
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
| |||
440 | 440 | | |
441 | 441 | | |
442 | 442 | | |
| 443 | + | |
443 | 444 | | |
444 | | - | |
| 445 | + | |
445 | 446 | | |
446 | 447 | | |
447 | 448 | | |
| |||
0 commit comments