Skip to content

Commit ed922ec

Browse files
committed
perf(language_server): avoid creating HashMap in Backend::did_change_watched_files (#14735)
The URI is only valid for one worker, so use a `Vec` to avoid transforming into a `Vec` later.
1 parent 14de671 commit ed922ec

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

crates/oxc_language_server/src/backend.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,9 @@ impl LanguageServer for Backend {
403403
let workers = self.workspace_workers.read().await;
404404
// ToDo: what if an empty changes flag is passed?
405405
debug!("watched file did change");
406-
let all_diagnostics: papaya::HashMap<String, Vec<Diagnostic>, FxBuildHasher> =
407-
ConcurrentHashMap::default();
406+
407+
let mut all_diagnostics = Vec::new();
408+
408409
for file_event in &params.changes {
409410
// We do not expect multiple changes from the same workspace folder.
410411
// If we should consider it, we need to map the events to the workers first,
@@ -418,24 +419,15 @@ impl LanguageServer for Backend {
418419
continue;
419420
};
420421

421-
for (key, value) in &diagnostics.pin() {
422+
for (uri, reports) in &diagnostics.pin() {
422423
all_diagnostics
423-
.pin()
424-
.insert(key.clone(), value.iter().map(|d| d.diagnostic.clone()).collect());
424+
.push((uri.clone(), reports.iter().map(|d| d.diagnostic.clone()).collect()));
425425
}
426426
}
427427

428-
if all_diagnostics.is_empty() {
429-
return;
428+
if !all_diagnostics.is_empty() {
429+
self.publish_all_diagnostics(&all_diagnostics).await;
430430
}
431-
432-
let x = &all_diagnostics
433-
.pin()
434-
.into_iter()
435-
.map(|(key, value)| (key.clone(), value.clone()))
436-
.collect::<Vec<_>>();
437-
438-
self.publish_all_diagnostics(x).await;
439431
}
440432

441433
/// The server will start new [WorkspaceWorker]s for added workspace folders

0 commit comments

Comments
 (0)