From 528a0bcf9b0e4ad1e89d21c9c8df3c55aa3ade00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Muska=C5=82a?= Date: Wed, 17 Feb 2021 12:38:11 +0100 Subject: Avoid transmitting unchanged diagnostics Reading through the code for diagnostics and observing debug logs, I noticed that diagnostics are transmitted after every change for every opened file, even if they haven't changed (especially visible for files with no diagnostics). This change avoids marking files as "changed" if diagnostics are the same to what was already sent before. This will only work if diagnostics are always produced in the same order, but from my limited testing it seems this is the case. --- crates/rust-analyzer/src/diagnostics.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/rust-analyzer/src/diagnostics.rs b/crates/rust-analyzer/src/diagnostics.rs index ee6f2a867..f01548c50 100644 --- a/crates/rust-analyzer/src/diagnostics.rs +++ b/crates/rust-analyzer/src/diagnostics.rs @@ -65,6 +65,17 @@ impl DiagnosticCollection { file_id: FileId, diagnostics: Vec, ) { + if let Some(existing_diagnostics) = self.native.get(&file_id) { + if existing_diagnostics.len() == diagnostics.len() + && diagnostics + .iter() + .zip(existing_diagnostics) + .all(|(new, existing)| are_diagnostics_equal(new, existing)) + { + return; + } + } + self.native.insert(file_id, diagnostics); self.changes.insert(file_id); } -- cgit v1.2.3