diff --git a/Cargo.lock b/Cargo.lock index d8f184642fe09..68a65890f115b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1827,7 +1827,6 @@ dependencies = [ "bitflags 2.8.0", "convert_case", "cow-utils", - "dashmap 6.1.0", "fast-glob", "globset", "ignore", @@ -1853,6 +1852,7 @@ dependencies = [ "oxc_semantic", "oxc_span", "oxc_syntax", + "papaya", "phf", "project-root", "rayon", @@ -2060,9 +2060,9 @@ dependencies = [ [[package]] name = "oxc_resolver" -version = "4.1.0" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ebc46f1d5b6be61afc868187dd5ee30829fb681f34643dabfbc5a6067e2fc49" +checksum = "b1c4d9cffbd24c3a874bd44cce4384cb73bf732c4fe4aa99c4406b2e0c4027bb" dependencies = [ "cfg-if", "indexmap", @@ -2293,9 +2293,9 @@ dependencies = [ [[package]] name = "papaya" -version = "0.1.8" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc7c76487f7eaa00a0fc1d7f88dc6b295aec478d11b0fc79f857b62c2874124c" +checksum = "aab21828b6b5952fdadd6c377728ffae53ec3a21b2febc47319ab65741f7e2fd" dependencies = [ "equivalent", "seize", @@ -2776,9 +2776,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "seize" -version = "0.4.9" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d84b0c858bdd30cb56f5597f8b3bf702ec23829e652cc636a1e5a7b9de46ae93" +checksum = "e4b8d813387d566f627f3ea1b914c068aac94c40ae27ec43f5f33bde65abefe7" dependencies = [ "libc", "windows-sys 0.52.0", diff --git a/Cargo.toml b/Cargo.toml index a64c8a5259b51..9d35741b9973c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -173,6 +173,7 @@ mimalloc = "0.1.43" nonmax = "0.5.5" num-bigint = "0.4.6" num-traits = "0.2.19" +papaya = "0.2.0" petgraph = "0.7.1" phf = "0.11.3" pico-args = "0.5.0" diff --git a/crates/oxc_linter/Cargo.toml b/crates/oxc_linter/Cargo.toml index 1dc627947df99..d5b3e9774fdc9 100644 --- a/crates/oxc_linter/Cargo.toml +++ b/crates/oxc_linter/Cargo.toml @@ -39,7 +39,6 @@ oxc_syntax = { workspace = true, features = ["serialize"] } bitflags = { workspace = true } convert_case = { workspace = true } cow-utils = { workspace = true } -dashmap = { workspace = true } fast-glob = { workspace = true } globset = { workspace = true } ignore = { workspace = true } @@ -49,6 +48,7 @@ language-tags = { workspace = true } lazy_static = { workspace = true } memchr = { workspace = true } nonmax = { workspace = true } +papaya = { workspace = true } phf = { workspace = true, features = ["macros"] } rayon = { workspace = true } regex = { workspace = true } diff --git a/crates/oxc_linter/src/service/module_cache.rs b/crates/oxc_linter/src/service/module_cache.rs index d2721c69d463a..2035d81a2239e 100644 --- a/crates/oxc_linter/src/service/module_cache.rs +++ b/crates/oxc_linter/src/service/module_cache.rs @@ -5,12 +5,12 @@ use std::{ sync::{Arc, Condvar, Mutex}, }; -use dashmap::{mapref::one::Ref, DashMap}; +use papaya::HashMap; use rustc_hash::{FxBuildHasher, FxHashMap}; use crate::ModuleRecord; -type FxDashMap = DashMap; +type FxDashMap = HashMap; /// `CacheState` and `CacheStateEntry` are used to fix the problem where /// there is a brief moment when a concurrent fetch can miss the cache. @@ -21,7 +21,7 @@ type FxDashMap = DashMap; /// /// See the "problem section" in /// and the solution is copied here to fix the issue. -type CacheState = Mutex, Arc<(Mutex, Condvar)>>>; +type CacheState = Mutex, Condvar)>>>; #[derive(Clone, Copy, Debug, Eq, PartialEq)] enum CacheStateEntry { @@ -47,8 +47,8 @@ pub(super) struct ModuleCache { impl ModuleCache { #[inline] - pub fn get(&self, path: &Path) -> Option> { - self.modules.get(path.as_os_str()) + pub fn get(&self, path: &Path) -> Option { + self.modules.pin().get(path.as_os_str()).cloned() } #[inline] @@ -59,9 +59,9 @@ impl ModuleCache { pub(super) fn init_cache_state(&self, path: &Path) -> bool { let (lock, cvar) = { let mut state_map = self.cache_state.lock().expect("Failed to lock cache state"); - &*Arc::clone(state_map.entry(path.to_path_buf().into_boxed_path()).or_insert_with( - || Arc::new((Mutex::new(CacheStateEntry::ReadyToConstruct), Condvar::new())), - )) + &*Arc::clone(state_map.entry(path.as_os_str().to_os_string()).or_insert_with(|| { + Arc::new((Mutex::new(CacheStateEntry::ReadyToConstruct), Condvar::new())) + })) }; let mut state = cvar .wait_while(lock.lock().expect("Failed lock inner cache state"), |state| { @@ -69,7 +69,7 @@ impl ModuleCache { }) .unwrap(); - let cache_hit = if self.modules.contains_key(path.as_os_str()) { + let cache_hit = if self.modules.pin().contains_key(path.as_os_str()) { true } else { let i = if let CacheStateEntry::PendingStore(i) = *state { i.get() } else { 0 }; @@ -89,14 +89,16 @@ impl ModuleCache { /// # Panics /// If a cache entry for `path` does not exist. You must call `init_cache_state` first. pub(super) fn add_resolved_module(&self, path: &Path, module_record: Arc) { - self.modules.insert(path.as_os_str().to_os_string(), ModuleState::Resolved(module_record)); + self.modules + .pin() + .insert(path.as_os_str().to_os_string(), ModuleState::Resolved(module_record)); self.update_cache_state(path); } /// # Panics /// If a cache entry for `path` does not exist. You must call `init_cache_state` first. pub(super) fn ignore_path(&self, path: &Path) { - self.modules.insert(path.as_os_str().to_os_string(), ModuleState::Ignored); + self.modules.pin().insert(path.as_os_str().to_os_string(), ModuleState::Ignored); self.update_cache_state(path); } @@ -107,7 +109,7 @@ impl ModuleCache { let mut state_map = self.cache_state.lock().expect("Failed to lock cache state"); &*Arc::clone( state_map - .get_mut(path) + .get_mut(path.as_os_str()) .expect("Entry in http-cache state to have been previously inserted"), ) }; diff --git a/crates/oxc_linter/src/service/runtime.rs b/crates/oxc_linter/src/service/runtime.rs index b78e54472b64f..3561ceb3cb454 100644 --- a/crates/oxc_linter/src/service/runtime.rs +++ b/crates/oxc_linter/src/service/runtime.rs @@ -253,14 +253,14 @@ impl Runtime { let path = resolution.path(); self.process_path(path, tx_error); // Append target_module to loaded_modules - if let Some(target_ref) = self.modules.get(path) { - if let ModuleState::Resolved(target_module_record) = target_ref.value() { - module_record - .loaded_modules - .write() - .unwrap() - .insert(specifier.clone(), Arc::clone(target_module_record)); - } + if let Some(ModuleState::Resolved(target_module_record)) = + self.modules.get(path) + { + module_record + .loaded_modules + .write() + .unwrap() + .insert(specifier.clone(), Arc::clone(&target_module_record)); }; });