Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(linter): use OsString for module cache hash #7558

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions crates/oxc_linter/src/service/module_cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
ffi::OsString,
num::NonZeroUsize,
path::Path,
sync::{Arc, Condvar, Mutex},
Expand Down Expand Up @@ -29,7 +30,8 @@ enum CacheStateEntry {
}

/// Keyed by canonicalized path
type ModuleMap = FxDashMap<Box<Path>, ModuleState>;
/// `OsString` hash is after than `Path` - go checkout their source code.
type ModuleMap = FxDashMap<OsString, ModuleState>;

#[derive(Clone)]
pub(super) enum ModuleState {
Expand All @@ -45,8 +47,8 @@ pub(super) struct ModuleCache {

impl ModuleCache {
#[inline]
pub fn get(&self, path: &Path) -> Option<Ref<'_, Box<Path>, ModuleState>> {
self.modules.get(path)
pub fn get(&self, path: &Path) -> Option<Ref<'_, OsString, ModuleState>> {
self.modules.get(path.as_os_str())
}

#[inline]
Expand All @@ -67,7 +69,7 @@ impl ModuleCache {
})
.unwrap();

let cache_hit = if self.modules.contains_key(path) {
let cache_hit = if self.modules.contains_key(path.as_os_str()) {
true
} else {
let i = if let CacheStateEntry::PendingStore(i) = *state { i.get() } else { 0 };
Expand All @@ -87,16 +89,14 @@ 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<ModuleRecord>) {
self.modules
.insert(path.to_path_buf().into_boxed_path(), ModuleState::Resolved(module_record));

self.modules.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.to_path_buf().into_boxed_path(), ModuleState::Ignored);
self.modules.insert(path.as_os_str().to_os_string(), ModuleState::Ignored);
self.update_cache_state(path);
}

Expand Down
Loading