Skip to content

Commit b3338a0

Browse files
committed
Cache path resolver, invalidating as necessary
Signed-off-by: Jonatan Waern <jonatan.waern@intel.com>
1 parent 3f2f5e6 commit b3338a0

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# Change Log
66

77
# 0.9.15
8-
8+
- Slight optimization in how the server resolves file paths, should reduce
9+
time-to-ready for the server when first starting by about 30%.
910

1011
## 0.9.14
1112
- Slight optimization to the memory usage of device-level analysis which

src/actions/mod.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ pub struct InitActionContext<O: Output> {
263263
// the root workspaces
264264
pub workspace_roots: Arc<Mutex<Vec<Workspace>>>,
265265

266+
pub cached_path_resolver: Arc<Mutex<Option<PathResolver>>>,
267+
266268
// directly opened files
267269
pub direct_opens: Arc<Mutex<HashSet<CanonPath>>>,
268270
pub compilation_info: Arc<Mutex<CompilationInfoStorage>>,
@@ -378,6 +380,7 @@ impl <O: Output> InitActionContext<O> {
378380
config,
379381
lint_config: Arc::new(Mutex::new(LintCfg::default())),
380382
jobs: Arc::default(),
383+
cached_path_resolver: Arc::default(),
381384
direct_opens: Arc::default(),
382385
quiescent: Arc::new(AtomicBool::new(false)),
383386
prev_changes: Arc::default(),
@@ -419,12 +422,17 @@ impl <O: Output> InitActionContext<O> {
419422

420423
pub fn update_workspaces(&self,
421424
mut add: Vec<Workspace>,
422-
remove: Vec<Workspace>) {
425+
remove: Vec<Workspace>,
426+
out: &O) {
427+
let any_change = !(add.is_empty() && remove.is_empty());
423428
if let Ok(mut workspaces) = self.workspace_roots.lock() {
424429
workspaces.retain(|workspace|
425430
remove.iter().all(|rem|rem != workspace));
426431
workspaces.append(&mut add);
427432
}
433+
if any_change {
434+
self.update_compilation_info(out);
435+
}
428436
}
429437

430438
fn update_linter_config(&self, out: &O) {
@@ -445,6 +453,11 @@ impl <O: Output> InitActionContext<O> {
445453
trace!("Updating compile info");
446454
if let Ok(config) = self.config.lock() {
447455
if let Some(compile_info) = &config.compile_info_path {
456+
// Ensure resolver exists
457+
self.construct_resolver();
458+
// And then remove it from storage (invalidates it)
459+
let old_resolver = self.cached_path_resolver.lock()
460+
.expect("Failed to grab resolver").take().unwrap();
448461
if let Some(canon_path) = CanonPath::from_path_buf(
449462
compile_info.clone()) {
450463
let workspaces = self.workspace_roots.lock().unwrap();
@@ -468,8 +481,7 @@ impl <O: Output> InitActionContext<O> {
468481
*ci = compilation_info;
469482
}
470483
self.analysis.lock().unwrap()
471-
.update_all_context_dependencies(
472-
self.construct_resolver());
484+
.update_all_context_dependencies(old_resolver);
473485
},
474486
Err(e) => {
475487
error!("Failed to update compilation info: {}", e);
@@ -776,6 +788,10 @@ impl <O: Output> InitActionContext<O> {
776788
}
777789

778790
pub fn construct_resolver(&self) -> PathResolver {
791+
if let Some(resolver) = self.cached_path_resolver.lock()
792+
.unwrap().as_ref() {
793+
return resolver.clone();
794+
}
779795
trace!("About to construct resolver");
780796
let mut toret: PathResolver =
781797
self.client_capabilities.root.clone().into();
@@ -788,6 +804,7 @@ impl <O: Output> InitActionContext<O> {
788804
.into_iter().collect()))
789805
.collect());
790806
trace!("Constructed resolver: {:?}", toret);
807+
*self.cached_path_resolver.lock().unwrap() = Some(toret.clone());
791808
toret
792809
}
793810

src/actions/notifications.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ impl BlockingNotificationAction for DidChangeWorkspaceFolders {
262262
fn handle<O: Output>(
263263
params: DidChangeWorkspaceFoldersParams,
264264
ctx: &mut InitActionContext<O>,
265-
_out: O,
265+
out: O,
266266
) -> Result<(), ResponseError> {
267267
let added = params.event.added;
268268
let removed = params.event.removed;
269-
ctx.update_workspaces(added, removed);
269+
ctx.update_workspaces(added, removed, &out);
270270
Ok(())
271271
}
272272
}

src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl BlockingRequestAction for InitializeRequest {
270270
});
271271
}
272272
if let ActionContext::Init(ref mut initctx) = ctx {
273-
initctx.update_workspaces(workspaces, vec![]);
273+
initctx.update_workspaces(workspaces, vec![], &out);
274274
let temp_resolver = initctx.construct_resolver();
275275
for file in IMPLICIT_IMPORTS {
276276
debug!("Requesting analysis of builtin file {}", file);

0 commit comments

Comments
 (0)