deno
c16d80a8 - perf(lsp): cache lint and doc diagnostics per document module (#34875)

Commit
166 days ago
perf(lsp): cache lint and doc diagnostics per document module (#34875) Right now, the LSP regenerates lint diagnostics for every open file each time diagnostics are refreshed: https://github.com/denoland/deno/blob/ed3086e4b129843c13a009112cf21dfd05745905/cli/lsp/diagnostics.rs#L451 This means that after enough files are open (say 50), there is a noticeable delay when changing only a single file, since every open file is re-linted on each refresh. Lint diagnostics only depend on a file's own contents — not on other files — so they can be computed once and reused until the file changes. This PR caches lint (and `deno doc --lint`) diagnostics on the `DocumentModule` instance via a `OnceCell`. ### Why caching on the module instance is correct A new `DocumentModule` is created whenever: - the document content changes (the module map is keyed by the `OpenDocument` pointer, so a new version produces a new module), or - the lint configuration changes (every `refresh_linter_resolver()` call site is immediately followed by `refresh_documents_config()`, which resets the module maps and drops all cached modules). So the module instance is a sound cache key for content-only diagnostics, and the cache is invalidated automatically when either the file or the lint config changes. Cancelled computations return `Err` and are **not** cached (via `OnceCell::get_or_try_init`), so a cancelled lint/doc pass is recomputed on the next request rather than caching a partial/empty result. Legitimate empty results (parse errors, non-package-export files, etc.) are cached. ### What is not cached TypeScript and dependency diagnostics are intentionally left uncached, since they depend on other files in the graph. ### Testing Existing LSP lint/doc diagnostic tests pass (`lsp_lint*`, `lsp_doc_lint_diagnostics`, `lsp_code_actions_ignore_lint`, `lsp_diagnostics_*`). Closes #13578 Closes denoland/divybot#469 Co-authored-by: divybot <divybot@users.noreply.github.com> Co-authored-by: Divy Srivastava <me@littledivy.com>
Author
Parents
Loading