Skip to content

rust-analyzer: lightweight profile (disable cachePriming + cargo.auto…#1557

Open
davidcforbes wants to merge 1 commit into
oraios:mainfrom
davidcforbes:pr/rust-analyzer-lightweight
Open

rust-analyzer: lightweight profile (disable cachePriming + cargo.auto…#1557
davidcforbes wants to merge 1 commit into
oraios:mainfrom
davidcforbes:pr/rust-analyzer-lightweight

Conversation

@davidcforbes

Copy link
Copy Markdown

Fixes #1556.

Serena launches rust-analyzer with VS Code's full heavyweight initializationOptions, hardcoded. On a large, actively-built Rust workspace these drive rust-analyzer to 40+ GB resident and trigger a full re-index on every external cargo build, even with no editor running. Serena's symbol tools don't need the two eager/auto re-indexing drivers:

  • cachePriming.enable: TrueFalse (no eager whole-workspace + all-deps index — the dominant contributor to the 40 GB resident set)
  • cargo.autoreload: TrueFalse (no re-index storm on target/ / Cargo metadata changes)

checkOnSave is intentionally left enabled

It is tempting to also disable checkOnSave for a lightweight profile, but doing so breaks get_diagnostics_for_file for Rust: rust-analyzer's diagnostics for ordinary errors (e.g. an unresolved name → E0425) come from flycheck (cargo check), and with checkOnSave: false Serena's pull-diagnostics request comes back empty — test/solidlsp/rust/test_rust_diagnostics.py::test_file_diagnostics fails with []. checkOnSave only spawns transient cargo check child processes and is not a driver of rust-analyzer's resident RSS, so keeping it on preserves diagnostics at no meaningful memory cost.

Ideally these would be exposed as a config toggle (per-language language_server_options, or a global lightweight / symbol_only flag) rather than hardcoded, so users who want the full RA feature set can opt in. Happy to rework toward that if preferred.

Testing

uv run --extra dev pytest test/solidlsp/rust/26 passed, 5 skipped on Windows 11 (Rust stable 1.95, rust-analyzer from rustup). Bisected to confirm cachePriming/autoreload are the memory drivers and checkOnSave is required for the diagnostics test.

…reload)

serena's symbol tools (find_symbol, find_referencing_symbols, …) only need the
symbol index, but the LSP is launched with VS Code's full heavyweight defaults.
On a large, actively-built Rust workspace these drove rust-analyzer to 40+ GB
RSS and triggered a full re-index on every external `cargo build` (target/
churn). Disabling the two eager/auto re-indexing drivers keeps symbol
navigation working at a fraction of the memory:

- cachePriming.enable: True -> False  (no eager whole-workspace+deps index)
- cargo.autoreload:    True -> False  (no re-index storm on target/ changes)

checkOnSave is intentionally LEFT enabled: serena's get_diagnostics_for_file
relies on flycheck (`cargo check`) for Rust diagnostics, and disabling it makes
that tool return empty (test/solidlsp/rust/test_rust_diagnostics.py fails with
[]). checkOnSave only spawns transient `cargo check` child processes and is not
a driver of rust-analyzer's resident RSS, so keeping it on preserves
diagnostics at no meaningful memory cost.

Observed on a rustback (multi-crate + rustic_core fork) workspace: repeated
40-44 GB rust-analyzer processes under serena with no VS Code present. Suggest
upstream expose a "lightweight"/symbol-only RA profile or a config toggle.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@MischaPanch

Copy link
Copy Markdown
Member

Thanks, that makes sense and helps us - we noticed the slow startup on large rust projects.

On ubuntu a rust diagnostics test fails, it's probably related to your change, could you look into it?

FAILED test/solidlsp/rust/test_rust_diagnostics.py::TestRustDiagnostics::test_file_diagnostics[rust] - AssertionError: []
= 1 failed, 1475 passed, 78 skipped, 6 xfailed, 9 xpassed, 1 warning in 1267.08s (0:21:07) =

@MischaPanch

Copy link
Copy Markdown
Member

Seems like we just need to bump the timeout, see #1559

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rust-analyzer: unbounded memory (40+ GB) on large Rust workspaces — hardcoded heavyweight init options

2 participants