Skip to content

Commit 62b3c27

Browse files
committed
Turbopack: parallel drop data before shutdown
1 parent 9539f87 commit 62b3c27

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ use crate::{
6464
InProgressCellState, InProgressState, InProgressStateInner, OutputValue, RootType,
6565
},
6666
utils::{
67-
bi_map::BiMap, chunked_vec::ChunkedVec, ptr_eq_arc::PtrEqArc, sharded::Sharded, swap_retain,
67+
bi_map::BiMap, chunked_vec::ChunkedVec, dash_map_drop_contents::drop_contents,
68+
ptr_eq_arc::PtrEqArc, sharded::Sharded, swap_retain,
6869
},
6970
};
7071

@@ -1216,6 +1217,9 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
12161217
self.is_idle.store(false, Ordering::Release);
12171218
self.verify_aggregation_graph(turbo_tasks, false);
12181219
}
1220+
self.task_cache.drop_contents();
1221+
drop_contents(&self.transient_tasks);
1222+
self.storage.drop_contents();
12191223
if let Err(err) = self.backing_storage.shutdown() {
12201224
println!("Shutting down failed: {err}");
12211225
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use crate::{
1616
CachedDataItemValue, CachedDataItemValueRef, CachedDataItemValueRefMut, OutputValue,
1717
},
1818
data_storage::{AutoMapStorage, OptionStorage},
19-
utils::dash_map_multi::{RefMut, get_multiple_mut},
19+
utils::{
20+
dash_map_drop_contents::drop_contents,
21+
dash_map_multi::{RefMut, get_multiple_mut},
22+
},
2023
};
2124

2225
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -806,6 +809,11 @@ impl Storage {
806809
},
807810
)
808811
}
812+
813+
pub fn drop_contents(&self) {
814+
drop_contents(&self.map);
815+
drop_contents(&self.modified);
816+
}
809817
}
810818

811819
pub struct StorageWriteGuard<'a> {

turbopack/crates/turbo-tasks-backend/src/utils/bi_map.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::{borrow::Borrow, hash::Hash};
33
use dashmap::mapref::entry::Entry;
44
use turbo_tasks::FxDashMap;
55

6+
use crate::utils::dash_map_drop_contents::drop_contents;
7+
68
/// A bidirectional [`FxDashMap`] that allows lookup by key or value.
79
///
810
/// As keys and values are stored twice, they should be small types, such as
@@ -53,3 +55,14 @@ where
5355
}
5456
}
5557
}
58+
59+
impl<K, V> BiMap<K, V>
60+
where
61+
K: Eq + Hash + Send + Sync,
62+
V: Eq + Hash + Send + Sync,
63+
{
64+
pub fn drop_contents(&self) {
65+
drop_contents(&self.forward);
66+
drop_contents(&self.reverse);
67+
}
68+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::{
2+
hash::{BuildHasher, Hash},
3+
mem::take,
4+
};
5+
6+
use dashmap::DashMap;
7+
use rayon::prelude::*;
8+
9+
pub fn drop_contents<K: Hash + Eq + Send + Sync, V: Send + Sync, H: BuildHasher + Clone>(
10+
map: &DashMap<K, V, H>,
11+
) {
12+
let shards = map.shards();
13+
shards.par_iter().for_each(|shard| {
14+
let table = take(&mut *shard.write());
15+
drop(table);
16+
});
17+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod bi_map;
22
pub mod chunked_vec;
3+
pub mod dash_map_drop_contents;
34
pub mod dash_map_multi;
45
pub mod ptr_eq_arc;
56
pub mod sharded;

0 commit comments

Comments
 (0)