Skip to content

Commit db96536

Browse files
committed
Decrease the size of turbo task object ids to u16
This probably doesn't save much memory but will save persistent db space
1 parent 00987df commit db96536

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

turbopack/crates/turbo-tasks/src/id.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ macro_rules! define_id {
119119
}
120120

121121
define_id!(TaskId: u32, derive(Serialize, Deserialize), serde(transparent));
122-
define_id!(FunctionId: u32);
123-
define_id!(ValueTypeId: u32);
124-
define_id!(TraitTypeId: u32);
122+
define_id!(FunctionId: u16);
123+
define_id!(ValueTypeId: u16);
124+
define_id!(TraitTypeId: u16);
125125
define_id!(SessionId: u32, derive(Debug, Serialize, Deserialize), serde(transparent));
126126
define_id!(
127127
LocalTaskId: u32,
@@ -166,7 +166,7 @@ macro_rules! make_serializable {
166166
where
167167
S: serde::Serializer,
168168
{
169-
serializer.serialize_u32(self.id.into())
169+
serializer.serialize_u16(self.id.into())
170170
}
171171
}
172172

@@ -175,7 +175,7 @@ macro_rules! make_serializable {
175175
where
176176
D: serde::Deserializer<'de>,
177177
{
178-
deserializer.deserialize_u32($visitor_name)
178+
deserializer.deserialize_u16($visitor_name)
179179
}
180180
}
181181

@@ -188,7 +188,7 @@ macro_rules! make_serializable {
188188
formatter.write_str(concat!("an id of a registered ", stringify!($ty)))
189189
}
190190

191-
fn visit_u32<E>(self, v: u32) -> Result<Self::Value, E>
191+
fn visit_u16<E>(self, v: u16) -> Result<Self::Value, E>
192192
where
193193
E: serde::de::Error,
194194
{
@@ -200,7 +200,7 @@ macro_rules! make_serializable {
200200
Ok(value)
201201
}
202202
}
203-
None => Err(E::unknown_variant(&format!("{v}"), &["a non zero u32"])),
203+
None => Err(E::unknown_variant(&format!("{v}"), &["a non zero u16"])),
204204
}
205205
}
206206
}

turbopack/crates/turbo-tasks/src/registry.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::num::NonZeroU32;
1+
use std::num::NonZeroU16;
22

33
use anyhow::Error;
44
use once_cell::sync::Lazy;
@@ -25,7 +25,7 @@ static FUNCTIONS: Lazy<Functions> = Lazy::new(|| {
2525
let mut value_to_id = FxHashMap::with_capacity_and_hasher(functions.len(), Default::default());
2626
let mut names = FxHashSet::with_capacity_and_hasher(functions.len(), Default::default());
2727

28-
let mut id = NonZeroU32::MIN;
28+
let mut id = NonZeroU16::MIN;
2929
for &native_function in functions.iter() {
3030
value_to_id.insert(native_function, id.into());
3131
let global_name = native_function.global_name;
@@ -84,7 +84,7 @@ static VALUES: Lazy<Values> = Lazy::new(|| {
8484
// Our sort above is non-sensical if names are not unique
8585
let mut names = FxHashSet::with_capacity_and_hasher(all_values.len(), Default::default());
8686

87-
let mut id = NonZeroU32::MIN;
87+
let mut id = NonZeroU16::MIN;
8888
for &value_type in all_values.iter() {
8989
value_to_id.insert(value_type, id.into());
9090
let global_name = value_type.global_name;
@@ -140,7 +140,7 @@ static TRAITS: Lazy<Traits> = Lazy::new(|| {
140140
let mut trait_to_id = FxHashMap::with_capacity_and_hasher(all_traits.len(), Default::default());
141141
// Our sort above is non-sensical if names are not unique
142142
let mut names = FxHashSet::with_capacity_and_hasher(all_traits.len(), Default::default());
143-
let mut id = NonZeroU32::MIN;
143+
let mut id = NonZeroU16::MIN;
144144
for &trait_type in all_traits.iter() {
145145
trait_to_id.insert(trait_type, id.into());
146146

0 commit comments

Comments
 (0)