Skip to content

Commit 0733e4c

Browse files
authored
perf: use dashmap to reduce lock contention (#10878)
1 parent 73be1ea commit 0733e4c

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

crates/rspack_core/src/artifacts/module_graph_cache_artifact.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,32 +150,26 @@ pub(super) mod get_side_effects_connection_state {
150150
}
151151

152152
pub(super) mod get_exports_type {
153-
use super::*;
154153
use crate::{ExportsType, ModuleIdentifier};
155154

156155
pub type GetExportsTypeCacheKey = (ModuleIdentifier, bool);
157156

158157
#[derive(Debug, Default)]
159158
pub struct GetExportsTypeCache {
160-
cache: RwLock<HashMap<GetExportsTypeCacheKey, ExportsType>>,
159+
cache: dashmap::DashMap<GetExportsTypeCacheKey, ExportsType>,
161160
}
162161

163162
impl GetExportsTypeCache {
164163
pub fn freeze(&self) {
165-
self.cache.write().expect("should get lock").clear();
164+
self.cache.clear();
166165
}
167166

168167
pub fn get(&self, key: &GetExportsTypeCacheKey) -> Option<ExportsType> {
169-
let inner = self.cache.read().expect("should get lock");
170-
inner.get(key).copied()
168+
self.cache.get(key).map(|x| *x)
171169
}
172170

173171
pub fn set(&self, key: GetExportsTypeCacheKey, value: ExportsType) {
174-
self
175-
.cache
176-
.write()
177-
.expect("should get lock")
178-
.insert(key, value);
172+
self.cache.insert(key, value);
179173
}
180174
}
181175
}

0 commit comments

Comments
 (0)