Skip to content

Commit bb05d1a

Browse files
committed
Do not unnecessarily re-trigger garbage collection if no inputs have changed
1 parent 2cf8bfe commit bb05d1a

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

crates/rust-analyzer/src/global_state.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use hir::ChangeWithProcMacros;
1515
use ide::{Analysis, AnalysisHost, Cancellable, FileId, SourceRootId};
1616
use ide_db::{
1717
MiniCore,
18-
base_db::{Crate, ProcMacroPaths, SourceDatabase},
18+
base_db::{Crate, ProcMacroPaths, SourceDatabase, salsa::Revision},
1919
};
2020
use itertools::Itertools;
2121
use load_cargo::SourceRootConfig;
@@ -194,12 +194,13 @@ pub(crate) struct GlobalState {
194194
pub(crate) incomplete_crate_graph: bool,
195195

196196
pub(crate) minicore: MiniCoreRustAnalyzerInternalOnly,
197+
pub(crate) last_gc_revision: Revision,
197198
}
198199

199200
// FIXME: This should move to the VFS once the rewrite is done.
200201
#[derive(Debug, Clone, Default)]
201202
pub(crate) struct MiniCoreRustAnalyzerInternalOnly {
202-
pub(crate) minicore_text: Option<String>,
203+
pub(crate) minicore_text: Option<Arc<str>>,
203204
}
204205

205206
/// An immutable snapshot of the world's state at a point in time.
@@ -256,6 +257,8 @@ impl GlobalState {
256257

257258
let (discover_sender, discover_receiver) = unbounded();
258259

260+
let last_gc_revision = analysis_host.raw_database().nonce_and_revision().1;
261+
259262
let mut this = GlobalState {
260263
sender,
261264
req_queue: ReqQueue::default(),
@@ -319,6 +322,7 @@ impl GlobalState {
319322
incomplete_crate_graph: false,
320323

321324
minicore: MiniCoreRustAnalyzerInternalOnly::default(),
325+
last_gc_revision,
322326
};
323327
// Apply any required database inputs from the config.
324328
this.update_configuration(config);

crates/rust-analyzer/src/main_loop.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,14 @@ impl GlobalState {
536536
self.update_tests();
537537
}
538538

539+
let current_revision = self.analysis_host.raw_database().nonce_and_revision().1;
539540
// no work is currently being done, now we can block a bit and clean up our garbage
540-
if self.task_pool.handle.is_empty() && self.fmt_pool.handle.is_empty() {
541+
if self.task_pool.handle.is_empty()
542+
&& self.fmt_pool.handle.is_empty()
543+
&& current_revision != self.last_gc_revision
544+
{
541545
self.analysis_host.trigger_garbage_collection();
546+
self.last_gc_revision = current_revision;
542547
}
543548
}
544549

@@ -912,7 +917,8 @@ impl GlobalState {
912917
// Not a lot of bad can happen from mistakenly identifying `minicore`, so proceed with that.
913918
self.minicore.minicore_text = contents
914919
.as_ref()
915-
.and_then(|contents| String::from_utf8(contents.clone()).ok());
920+
.and_then(|contents| str::from_utf8(contents).ok())
921+
.map(triomphe::Arc::from);
916922
}
917923

918924
let path = VfsPath::from(path);

0 commit comments

Comments
 (0)