Skip to content

Commit

Permalink
perf: prefetch package index for completion (#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin authored Dec 11, 2024
1 parent 4f5c9c7 commit a86f7a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/tinymist-world/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ impl PackageStorage {
}
}

/// Get the cached package index without network access.
pub fn cached_index(&self) -> Option<&[(PackageSpec, Option<EcoString>)]> {
self.index.get().map(Vec::as_slice)
}

/// Download the package index. The result of this is cached for efficiency.
pub fn download_index(&self) -> &[(PackageSpec, Option<EcoString>)] {
self.index.get_or_init(|| {
Expand Down
10 changes: 10 additions & 0 deletions crates/tinymist/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,16 @@ impl LanguageState {
}
fut_stat.stat.snap();

if matches!(query, Completion(..)) {
// Prefetch the package index for completion.
if snap.world.registry.cached_index().is_none() {
let registry = snap.world.registry.clone();
tokio::spawn(async move {
let _ = registry.download_index();
});
}
}

match query {
SemanticTokensFull(req) => snap.run_semantic(req, R::SemanticTokensFull),
SemanticTokensDelta(req) => snap.run_semantic(req, R::SemanticTokensDelta),
Expand Down

0 comments on commit a86f7a4

Please sign in to comment.