perf: add cache for docstrings (#1877)
Some checks are pending
tinymist::ci / build-vscode-others (push) Blocked by required conditions
tinymist::ci / publish-vscode (push) Blocked by required conditions
tinymist::ci / Duplicate Actions Detection (push) Waiting to run
tinymist::ci / Check Clippy, Formatting, Completion, Documentation, and Tests (Linux) (push) Waiting to run
tinymist::ci / Check Minimum Rust version and Tests (Windows) (push) Waiting to run
tinymist::ci / E2E Tests (darwin-arm64 on macos-latest) (push) Blocked by required conditions
tinymist::ci / E2E Tests (linux-x64 on ubuntu-22.04) (push) Blocked by required conditions
tinymist::ci / E2E Tests (linux-x64 on ubuntu-latest) (push) Blocked by required conditions
tinymist::ci / E2E Tests (win32-x64 on windows-2022) (push) Blocked by required conditions
tinymist::ci / E2E Tests (win32-x64 on windows-latest) (push) Blocked by required conditions
tinymist::ci / prepare-build (push) Waiting to run
tinymist::ci / build-binary (push) Blocked by required conditions
tinymist::ci / build-vsc-assets (push) Blocked by required conditions
tinymist::ci / build-vscode (push) Blocked by required conditions
tinymist::gh_pages / build-gh-pages (push) Waiting to run

This commit is contained in:
Myriad-Dreamin 2025-07-07 02:16:11 +08:00 committed by GitHub
parent 4426b31ed7
commit 355fac08bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 12 deletions

View file

@ -8,6 +8,7 @@ use comemo::{Track, Tracked};
use lsp_types::Url;
use parking_lot::Mutex;
use rustc_hash::FxHashMap;
use tinymist_analysis::docs::DocString;
use tinymist_analysis::stats::AllocStats;
use tinymist_analysis::ty::term_value;
use tinymist_analysis::{analyze_expr_, analyze_import_};
@ -163,6 +164,7 @@ impl Analysis {
/// Clear all cached resources.
pub fn clear_cache(&self) {
self.caches.signatures.clear();
self.caches.docstrings.clear();
self.caches.def_signatures.clear();
self.caches.static_signatures.clear();
self.caches.terms.clear();
@ -289,6 +291,7 @@ impl LocalContextGuard {
caches.static_signatures.retain(|(l, _)| retainer(*l));
caches.terms.retain(|(l, _)| retainer(*l));
caches.signatures.retain(|(l, _)| retainer(*l));
caches.docstrings.retain(|(l, _)| retainer(*l));
}
}
@ -969,6 +972,23 @@ impl SharedContext {
res.get_or_init(|| compute(self)).clone()
}
pub(crate) fn compute_docstring(
self: &Arc<Self>,
fid: TypstFileId,
docs: String,
kind: DefKind,
) -> Option<Arc<DocString>> {
let res = self
.analysis
.caches
.docstrings
.entry(hash128(&(fid, &docs, kind)), self.lifetime);
res.get_or_init(|| {
crate::syntax::docs::do_compute_docstring(self, fid, docs, kind).map(Arc::new)
})
.clone()
}
/// Remove html tags from markup content if necessary.
pub fn remove_html(&self, markup: EcoString) -> EcoString {
if !self.analysis.remove_html {
@ -1163,6 +1183,7 @@ pub struct AnalysisGlobalCaches {
def_signatures: CacheMap<DeferredCompute<Option<Signature>>>,
static_signatures: CacheMap<DeferredCompute<Option<Signature>>>,
signatures: CacheMap<DeferredCompute<Option<Signature>>>,
docstrings: CacheMap<DeferredCompute<Option<Arc<DocString>>>>,
terms: CacheMap<(Value, Ty)>,
}