Unverified Commit 0af459d0 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Turbopack: widen the chunk ident hash from 7 to 10 base38 chars

7 base38 chars (~36 bits nominal, ~32 effective) makes chunk-name collisions
a birthday problem for large apps: ~10^5 chunks sharing a name prefix collide
with probability of order 1, and next build aborts with 'Two or more assets
with different content were emitted to the same output path'.

Fixes the failure reported in #97765 (deterministic repro) and #96976.
Co-authored-by: 's avatarjonnyuniverse <jon@fractionalventure.partners>
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent 80576037
...@@ -293,8 +293,17 @@ impl AssetIdent { ...@@ -293,8 +293,17 @@ impl AssetIdent {
if has_hash { if has_hash {
let hash = encode_base38(hasher.finish()); let hash = encode_base38(hasher.finish());
// 7 base38 chars ≈ 36 bits of collision resistance // 10 base38 chars ≈ 52 bits of collision resistance.
let truncated_hash = &hash[..7]; //
// 7 chars (≈ 36 bits nominal, and closer to ~32 in practice because
// the leading character is bounded) is not enough for large apps:
// any population of chunks sharing a name prefix and distinguished
// only by this hash is a birthday problem, so ~10^5 such chunks
// collide with probability of order 1 and the build fails with
// "Two or more assets with different content were emitted to the
// same output path". Three extra characters drop that by ~5 orders
// of magnitude.
let truncated_hash = &hash[..10];
write!(name, "_{truncated_hash}")?; write!(name, "_{truncated_hash}")?;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment