rust-lang / rust-lang/rust-analyzer

`DidChangeTextDocument` notification is slow to process and may block

Open
#13,538 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-perf C-enhancement
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

We handle client to server notifications synchronously, which means we should make sure that these notifications are processed fast as otherwise the server will block on them. If a user opens a very large rust file (100k+ lines) they will start encountering overly long loop and the general editor experience becomes very laggy. We can't make the processing for this notification async unfortunately so we should try and optimize the things we do there instead.

Relevant code snippets:

https://github.com/rust-lang/rust-analyzer/blob/bbcb77ea6fc08df598b20267afd6a44018b21f5b/crates/rust-analyzer/src/main_loop.rs#L746-L768
https://github.com/rust-lang/rust-analyzer/blob/bbcb77ea6fc08df598b20267afd6a44018b21f5b/crates/rust-analyzer/src/lsp_utils.rs#L135-L183
https://github.com/rust-lang/rust-analyzer/blob/bbcb77ea6fc08df598b20267afd6a44018b21f5b/crates/ide-db/src/line_index.rs#L57-L94

The main part here is the LineIndex calculation as we have to traverse the entire document text character by character, so we should look into possibly optimizing the creation of it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the notification handling in crates/rust-analyzer/src/main_loop.rs and lsp_utils.rs, then inspect LineIndex creation in crates/ide-db/src/line_index.rs. Profile processing for a 100k+ line Rust file, focusing on the character-by-character LineIndex calculation. Done means the notification completes faster without changing its behavior or blocking the server as severely.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.