perf(cache): swap SHA-256 → xxHash3 (CACHE_VERSION v14→v15)#87
Merged
Conversation
…ON v14→v15) xxHash3 is ~5× faster than SHA-256 on modern x86 and produces enough entropy for our non-cryptographic uses: cache-key derivation, file content fingerprinting, config-load module cache-busting. None need collision resistance against an adversary — just uniqueness across honest input. Cache keys shrink 64 hex → 16 hex; Turbo uses the same width (xxh64 → hex(u64.to_be_bytes())). `Bun.hash.xxHash3` has no streaming Hasher API, so `Cache.key()` chains updates via the seed parameter — each `xxh3(part, prevDigest)` folds one field into the running digest, equivalent to the old `CryptoHasher.update(...).digest()` pattern with no intermediate buffer. `hashFileFromDisk` reads the whole file before hashing — fine for source files (typically < 1MB each); the throughput win dominates on the cache-warm path that hashes hundreds of them. Sites swapped: - src/cache/cache.ts: Cache.key(), hashFileFromDisk() - src/orchestrator/execute-task.ts: hashTaskConfig(), computeGroupHash() - src/orchestrator/fingerprint.ts: computeWorkspaceFingerprint() - src/workspace/project-loader.ts: config-load module cache-bust New shared helper at src/util/hash.ts exports `xxh3`, `xxh3hex`, `xxh3hexOf`. SCHEMA_VERSION bumps v12 → v13 in the same change: `file_hashes.sha256` column renamed to `content_hash`, and the schema-mismatch path now DROPs stale tables before CREATE TABLE IF NOT EXISTS runs so column renames take effect on existing DBs.
ac96db9 to
327abb5
Compare
4 tasks
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.
Summary
Bun.CryptoHasher) to xxHash3 (Bun.hash.xxHash3) at every derivation site. ~5× faster on the cache-warm path that hashes hundreds of input files; cache keys shrink 64 hex → 16 hex (Turbo parity — Turbo uses xxh64 at the same width).Cache.key()chains via the seed parameter: eachxxh3(part, prevDigest)folds one field into the running digest. Equivalent to the oldCryptoHasher.update(...).digest()pattern with no intermediate buffer.hashFileFromDiskreads the whole file before hashing — fine for source files (typically < 1MB); the throughput win dominates over streaming.src/util/hash.tsexportingxxh3/xxh3hex/xxh3hexOfso cache, orchestrator, and workspace modules can all consume it.SCHEMA_VERSIONv12 → v13:file_hashes.sha256column renamed tocontent_hash, and the migration path nowDROPs stale tables beforeCREATE TABLE IF NOT EXISTSruns so column renames actually take effect on existing DBs.Sites swapped
src/cache/cache.tsCache.key(),hashFileFromDisk()src/orchestrator/execute-task.tshashTaskConfig(),computeGroupHash()src/orchestrator/fingerprint.tscomputeWorkspaceFingerprint()src/workspace/project-loader.tsWhy xxHash3 (not Turbo's xxh64)
Both are non-cryptographic 64-bit hashes with 16-hex output. xxh3 is the newer variant, ~5-6× faster than xxh64 on a modern x86 core. The bytes are opaque to the remote cache server — it's just a key string — so there's no parity reason to match Turbo's exact algorithm. Faster wins.
Test plan
bun test src/ tests/— 462/462 greenbun src/bin.ts run lint— clean (one pre-existing unused-vars warning in the hardlink test, unrelated)bun src/bin.ts run format— cleantests/cache.test.ts+tests/cache-perf.test.tsrewritten to xxh3 referencesDROPthe stalefile_hashestable and recreate withcontent_hashcolumn on first openDocs
docs/caching.md— version history extended with the v14 → v15 entryCLAUDE.md— decision log entry at the topsrc/util/hash.ts— module-level comment explains the seed-chain pattern and why we picked xxh3https://claude.ai/code/session_016HXj6HW6bxSn8EYuKcxTD9
Generated by Claude Code