Skip to content

Commit 5bce803

Browse files
committed
perf: Request cancellation while processing changed files
1 parent d7e977a commit 5bce803

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

crates/rust-analyzer/src/global_state.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,21 +290,25 @@ impl GlobalState {
290290

291291
pub(crate) fn process_changes(&mut self) -> bool {
292292
let _p = span!(Level::INFO, "GlobalState::process_changes").entered();
293-
294293
// We cannot directly resolve a change in a ratoml file to a format
295294
// that can be used by the config module because config talks
296295
// in `SourceRootId`s instead of `FileId`s and `FileId` -> `SourceRootId`
297296
// mapping is not ready until `AnalysisHost::apply_changes` has been called.
298297
let mut modified_ratoml_files: FxHashMap<FileId, (ChangeKind, vfs::VfsPath)> =
299298
FxHashMap::default();
300299

301-
let (change, modified_rust_files, workspace_structure_change) = {
302-
let mut change = ChangeWithProcMacros::default();
303-
let mut guard = self.vfs.write();
304-
let changed_files = guard.0.take_changes();
305-
if changed_files.is_empty() {
306-
return false;
307-
}
300+
let mut change = ChangeWithProcMacros::default();
301+
let mut guard = self.vfs.write();
302+
let changed_files = guard.0.take_changes();
303+
if changed_files.is_empty() {
304+
return false;
305+
}
306+
307+
let (change, modified_rust_files, workspace_structure_change) = std::thread::scope(|s| {
308+
// start cancellation in parallel, this will kick off lru eviction
309+
// allowing us to do meaningful work while waiting
310+
// FIXME: We should have a long living thread for this purpose instead of re-spawning.
311+
s.spawn(|| self.analysis_host.request_cancellation());
308312

309313
// downgrade to read lock to allow more readers while we are normalizing text
310314
let guard = RwLockWriteGuard::downgrade_to_upgradable(guard);
@@ -387,9 +391,8 @@ impl GlobalState {
387391
change.set_roots(roots);
388392
}
389393
(change, modified_rust_files, workspace_structure_change)
390-
};
394+
});
391395

392-
let _p = span!(Level::INFO, "GlobalState::process_changes/apply_change").entered();
393396
self.analysis_host.apply_change(change);
394397
if !modified_ratoml_files.is_empty()
395398
|| !self.config.same_source_root_parent_map(&self.local_roots_parent_map)

0 commit comments

Comments
 (0)