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:
rust-analyzer/crates/rust-analyzer/src/main_loop.rs
Lines 746 to 768 in bbcb77e
rust-analyzer/crates/rust-analyzer/src/lsp_utils.rs
Lines 135 to 183 in bbcb77e
rust-analyzer/crates/ide-db/src/line_index.rs
Lines 57 to 94 in bbcb77e
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.