Skip to content

Commit ed75068

Browse files
committed
address review feedback
1 parent 0938c4c commit ed75068

2 files changed

Lines changed: 13 additions & 22 deletions

File tree

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
//! - `data` - Frequently changed bulk data (dependencies, cell data)
1818
//! - `meta` - Rarely changed metadata (output, aggregation, flags)
1919
//! - `transient` - Not serialized, only exists in memory
20-
use std::{hash::Hash, sync::Arc};
20+
use std::{
21+
hash::{BuildHasherDefault, Hash},
22+
sync::Arc,
23+
};
2124

2225
use parking_lot::Mutex;
26+
use rustc_hash::FxHasher;
2327
use turbo_tasks::{
2428
CellId, SharedReference, TaskExecutionReason, TaskId, TinyVec, TraitTypeId, ValueTypeId,
2529
backend::{CachedTaskTypeArc, CellHash, TransientTaskType},
@@ -36,20 +40,12 @@ use crate::{
3640
},
3741
};
3842

39-
/// Auto-set storage for small sets of keys with unit values.
40-
///
41-
/// The `I` const generic is the inline capacity — entries spill to a `HashSet`
42-
/// past it. Each field below picks its own `I` to saturate the available
43-
/// padding (in `LazyField`) or to stay within the 16-byte `SmallVec` free
44-
/// zone (for inline fields); see the field comments for the rationale.
45-
type AutoSet<K, const I: usize> =
46-
auto_hash_map::AutoSet<K, std::hash::BuildHasherDefault<rustc_hash::FxHasher>, I>;
43+
type AutoSet<K, const I: usize> = auto_hash_map::AutoSet<K, BuildHasherDefault<FxHasher>, I>;
4744

4845
/// Auto-map storage for key-value pairs.
4946
///
5047
/// See [`AutoSet`] for the meaning of `I`.
51-
type AutoMap<K, V, const I: usize> =
52-
auto_hash_map::AutoMap<K, V, std::hash::BuildHasherDefault<rustc_hash::FxHasher>, I>;
48+
type AutoMap<K, V, const I: usize> = auto_hash_map::AutoMap<K, V, BuildHasherDefault<FxHasher>, I>;
5349

5450
/// The complete task storage schema.
5551
///

turbopack/crates/turbo-tasks-macros/src/derive/task_storage_macro.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,17 +1297,12 @@ fn generate_typed_storage_struct(grouped_fields: &GroupedFields) -> TokenStream
12971297
};
12981298

12991299
let lazy_field = if has_lazy {
1300-
// `TinyVec`'s `MAX` const generic is set to the exact number of lazy fields declared
1301-
// in the schema. This caps growth at the smallest power-of-two-or-MAX boundary
1302-
// (e.g. with 24 variants we end at cap=24 instead of cap=32), saving a few slots
1303-
// per fully-populated task. It also makes "push past MAX" a compile-time-bounded
1304-
// contract instead of relying on `u8::MAX`.
1305-
//
1306-
// `as u8` cast is safe at the macro layer: u8::MAX is plenty of room for any
1307-
// realistic schema (asserted at compile time by `TinyVec::new`'s `MAX > 0` guard
1308-
// — a runtime check is not strictly required because the macro itself wouldn't
1309-
// emit > 255 variants).
1310-
let max_lazy = grouped_fields.all_lazy().count() as u8;
1300+
let max_lazy: u8 = grouped_fields
1301+
.all_lazy()
1302+
.count()
1303+
.try_into()
1304+
.expect("cannot have more than 255 lazy fields");
1305+
13111306
quote! {
13121307
#[doc = "Lazily-allocated fields stored in a compact TinyVec for memory efficiency"]
13131308
lazy: TinyVec<LazyField, #max_lazy>,

0 commit comments

Comments
 (0)