next.js
1561d4e8 - turbo-persistence: faster key block sorting (#100335)

Commit
8 hours ago
turbo-persistence: faster key block sorting (#100335) ## Summary `KeyOnly` key blocks with 4-byte and 8-byte keys were stably sorted as `&PendingEntry`, reading both keys through their entries on every comparison. Each key is now read once into a dense `(key << bits) | index` integer, and those integers are sorted unstably. The index keeps equal keys in their original order, preserving the stable order needed for tombstones. In the original profile, this roughly halved the sort of a full 4-byte-key block (6.96 → 3.78 µs). This also adds tests for `MergeIter`, covering ordering, newest-first equal keys, multi-value groups, input errors, and randomized comparisons against a sorted reference. AMQF fingerprint construction is unchanged. I compared `sort_by_key` against the existing `sort_unstable_by_key` there; on a full compaction of 16Mi 8-byte-key / 4-byte-value entries over 32 commits, the difference wasn't statistically significant (5.66 s vs 5.90 s, `p = 0.22`). ## Verification - `cargo test --features mmap` in `turbopack/crates/turbo-persistence` - `cargo fmt -- --check` - `cargo clippy --features mmap --all-targets -- -D warnings` <!-- NEXT_JS_LLM --> <!-- fleet af34fc25-1888-4720-a67e-66c65755551a --> --------- Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
Author
Parents
Loading