Skip to content

[WTF] Let the embedder key the string and integer hashes per process - #783

Draft
dylan-conway wants to merge 6 commits into
mainfrom
claude/per-process-hash-secrets
Draft

dylan-conway wants to merge 6 commits into
mainfrom
claude/per-process-hash-secrets

Conversation

@dylan-conway

@dylan-conway dylan-conway commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

StringHasher (rapidhash) and intHash are 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/Set and 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 hashed StringImpls 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):

ordinary Stable PerProcess
JSON.parse, as object keys 3 ms 2471 ms 3 ms
JSON.parse, as array values 2 ms 2047 ms 2 ms
new Set(strings) 1 ms 1541 ms 1 ms
new Set(integers), 16k 1 ms 134 ms 1 ms
JSON.parse, 16k index-like keys 2 ms 106 ms 2 ms

With Stable, what is generated or stored is used as before

A 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, and StringImpl::stableHash() is hash() when it is.

Stable PerProcess
Static property tables (.lut.h), Yarr's Unicode property tables generated index, looked up by the cached hash same index, looked up by stableHash(), computed per lookup
Bytecode cache: the hash in a string record, CachedUniquedStringImpl, CachedCompactTDZEnvironment stored and used, same format stored (stable), recomputed on decode; no atom-table prefetch
SourceProvider::hash(), PrelinkedModuleGraph's name hashes the cached hash stableHash()
VariableEnvironment, SymbolTable, private accessors, exported bindings (IdentifierRepStableHash), the parser's names for computed class members same order as before same order as Stable, so bytecode and Object.keys(globalThis) do not depend on the process
JIT (rapidHashMix64) the same constants this process's secrets

The one thing that changes with Stable too: a StaticStringImpl / StaticSymbolImpl no longer has its content hash from compile time, since one binary serves both choices and hash() 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 through StringHasher instead of Hasher.

PerProcess does what V8 does: one random 64-bit seed, wyhash's make_secret to turn it into the three secrets, and the seed itself as rapidhash's seed. The port gives the same secrets as V8's third_party/rapidhash-v8/secret.h for 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.h includes the headers that hash, so they cannot reach a field of WTF::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.
  • The JSC tests run with Stable. Nothing here runs them with PerProcess.

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.
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Preview build of 365a82b: autobuild-preview-pr-783-365a82bc

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.
@dylan-conway dylan-conway changed the title [WTF] Key the string and integer hashes with secrets picked per process [WTF] Let the embedder key the string and integer hashes per process Oct 9, 2026
wyhash's make_secret whole, from one random 64-bit seed, which also seeds rapidhash.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant