perf(oxlint/lsp): avoid second lock for getting/removing unused directives (#25350)

Avoids a second lock for `.map` inside `DirectivesStore` when consuming the directives on `--lsp` side.
This commit is contained in:
Sysix committed 2026-08-07 10:00:46 +00:00
1 parent 325856e4d4
commit 4ec9189b26
2 files changed
+12 -6

No files matched your search

+4 -6
View File
@@ -834,17 +834,15 @@ impl ServerLinter {
messages.append(&mut generate_inverted_diagnostics(&messages, uri));
// Take directives once to avoid separate get/remove lock acquisitions.
let directives = self.runner.directives_coordinator().take(path);
// Add unused directives if configured
if let Some(severity) = self.unused_directives_severity
&& let Some(directives) = self.runner.directives_coordinator().get(path)
&& let Some(directives) = directives
{
messages.extend(create_unused_directives_report(&directives, severity, source_text));
}
// Clear any stale directives because they are no longer needed.
// This prevents using outdated directive spans if the new linting run fails.
self.runner.directives_coordinator().remove(path);
Ok(messages)
}
+8
View File
@@ -127,6 +127,14 @@ impl DirectivesStore {
pub fn remove(&self, path: &Path) {
self.map.lock().expect("DirectivesStore mutex poisoned in remove").remove(path);
}
/// Take and remove disable directives for a specific file in a single lock acquisition.
///
/// # Panics
/// Panics if the mutex is poisoned.
pub fn take(&self, path: &Path) -> Option<DisableDirectives> {
self.map.lock().expect("DirectivesStore mutex poisoned in take").remove(path)
}
}
impl Default for DirectivesStore {