Skip to content

Commit dbced22

Browse files
committed
turbo-tasks: shard task_cache the same as storage.map
`task_cache: FxDashMap::default()` falls through to dashmap's default shard amount of `num_cpus * 4` (e.g. 64 shards on a 14-core machine), while `storage.map` uses our `compute_shard_amount` heuristic which is quadratic in worker count for a target ~3% collision probability (e.g. 4096 shards on the same machine). The 64× mismatch made `task_cache` lookups self-contend on every cache hit even when `storage.map` accesses were uncontended. Profiles attributed ~10% of overhead samples to `dashmap::lock_exclusive_slow` on `task_cache`'s shards, which is implausible for a properly sharded map at this thread count. Use `with_capacity_and_hasher_and_shard_amount` on `task_cache` with the same `shard_amount` we already pass to `Storage::new`.
1 parent e2e1d4f commit dbced22

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

  • turbopack/crates/turbo-tasks-backend/src/backend

turbopack/crates/turbo-tasks-backend/src/backend/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,15 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
239239
TaskId::try_from(TRANSIENT_TASK_BIT).unwrap(),
240240
TaskId::MAX,
241241
),
242-
task_cache: FxDashMap::default(),
242+
// Match `storage.map`'s shard count instead of falling through to dashmap's
243+
// default (`num_cpus * 4`). On a 14-core machine that default is 64 shards
244+
// versus our heuristic's 4096; the cache lookup path was contending with
245+
// itself on what should be cheap reads.
246+
task_cache: FxDashMap::with_capacity_and_hasher_and_shard_amount(
247+
0,
248+
Default::default(),
249+
shard_amount,
250+
),
243251
storage: Storage::new(shard_amount, small_preallocation),
244252
snapshot_coord: SnapshotCoordinator::new(),
245253
snapshot_in_progress: Mutex::new(()),

0 commit comments

Comments
 (0)