Skip to content

Commit

Permalink
box InnerStorage to avoid overallocation
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jan 24, 2025
1 parent 7aa6137 commit dee5be2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions turbopack/crates/turbo-tasks-backend/src/backend/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl InnerStorage {
}

pub struct Storage {
map: DashMap<TaskId, InnerStorage, BuildHasherDefault<FxHasher>>,
map: DashMap<TaskId, Box<InnerStorage>, BuildHasherDefault<FxHasher>>,
}

impl Storage {
Expand All @@ -315,7 +315,7 @@ impl Storage {
pub fn access_mut(&self, key: TaskId) -> StorageWriteGuard<'_> {
let inner = match self.map.entry(key) {
dashmap::mapref::entry::Entry::Occupied(e) => e.into_ref(),
dashmap::mapref::entry::Entry::Vacant(e) => e.insert(InnerStorage::new()),
dashmap::mapref::entry::Entry::Vacant(e) => e.insert(Box::new(InnerStorage::new())),
};
StorageWriteGuard {
inner: inner.into(),
Expand All @@ -327,7 +327,7 @@ impl Storage {
key1: TaskId,
key2: TaskId,
) -> (StorageWriteGuard<'_>, StorageWriteGuard<'_>) {
let (a, b) = get_multiple_mut(&self.map, key1, key2, InnerStorage::new);
let (a, b) = get_multiple_mut(&self.map, key1, key2, || Box::new(InnerStorage::new()));
(
StorageWriteGuard { inner: a },
StorageWriteGuard { inner: b },
Expand All @@ -336,7 +336,7 @@ impl Storage {
}

pub struct StorageWriteGuard<'a> {
inner: RefMut<'a, TaskId, InnerStorage>,
inner: RefMut<'a, TaskId, Box<InnerStorage>>,
}

impl Deref for StorageWriteGuard<'_> {
Expand Down

0 comments on commit dee5be2

Please sign in to comment.