Repository navigation
[WTF] Let the embedder key the string and integer hashes per process - #783
Draft
dylan-conway wants to merge 6 commits into
Draft
dylan-conway wants to merge 6 commits into
dylan-conway wants to merge 6 commits into
Conversation
StringHasher and intHash used rapidhash's published secrets, so keys that share their low hash bits shared them in every process. What relied on a hash known at build time (static strings, static property tables, the bytecode cache) now computes it at run time, and what a file stores uses StringHasher::computeStableHashAndMaskTop8Bits.
…ode and property enumeration InlineMap's hashed mode keeps its entries in insertion order. A for loop's scope copy and the names of a scope object's variables go by variable offset, private accessors and exported bindings by source order.
…omic_ref The Android NDK's libc++ has no std::atomic_ref.
|
Preview build of 365a82b: |
StringView::hash() differs from one process to the next, so the run that reads the cache looked for another file than the run that wrote it.
…ecrets used so far
wyhash's make_secret whole, from one random 64-bit seed, which also seeds rapidhash.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
StringHasher(rapidhash) andintHashare keyed with rapidhash's published secrets, so a key has the same hash in every process. A set of keys that happens to share its low hash bits therefore shares them everywhere, and n of those cost O(n²) in the atom table,PropertyTable,Map/Setand sparse array storage.The secrets are now data instead of constants (
wtf/HashSecrets.h).WTF::initializeHashSecrets(HashSecretsChoice)sets them once, before anything hashes:Stable, the default: the published secrets. Every hash, and so every table's order, is what it was.PerProcess: random ones. All threads share them, since hashedStringImpls cross threads.32,768 16-character keys that share one hash under the published secrets, next to 32,768 that do not (macOS arm64, release):
StablePerProcessJSON.parse, as object keysJSON.parse, as array valuesnew Set(strings)new Set(integers), 16kJSON.parse, 16k index-like keysWith
Stable, what is generated or stored is used as beforeA hash computed at build time or read from a file is made with the published secrets.
hashSecretsAreStable()says whether that is also what this process computes, andStringImpl::stableHash()ishash()when it is.StablePerProcess.lut.h), Yarr's Unicode property tablesstableHash(), computed per lookupCachedUniquedStringImpl,CachedCompactTDZEnvironmentSourceProvider::hash(),PrelinkedModuleGraph's name hashesstableHash()VariableEnvironment,SymbolTable, private accessors, exported bindings (IdentifierRepStableHash), the parser's names for computed class membersStable, so bytecode andObject.keys(globalThis)do not depend on the processrapidHashMix64)The one thing that changes with
Stabletoo: aStaticStringImpl/StaticSymbolImplno longer has its content hash from compile time, since one binary serves both choices andhash()returns whatever is there. It is computed on first use and added atomically. A static symbol's own hash (hashForSymbol()) is only ever compared with itself and stays a compile-time constant.JSBigInt::hash()goes throughStringHasherinstead ofHasher.PerProcessdoes what V8 does: one random 64-bit seed, wyhash'smake_secretto turn it into the three secrets, and the seed itself as rapidhash's seed. The port gives the same secrets as V8'sthird_party/rapidhash-v8/secret.hfor 400 seeds tried. It takes about 3.6 ms.The secrets live in
WebConfig::g_config, in a reservation of their own next to Gigacage's (WTFConfig.hincludes the headers that hash, so they cannot reach a field ofWTF::Config). They are frozen with the rest of the page.Still to do
TestWebKitAPI's WTF tests are updated (RapidHash,StringImpl) but have not been built.Stable. Nothing here runs them withPerProcess.