rust-lang / rust-lang/rust-analyzer

Slow auto-complete / semantic highlighting with async function and lots of expressions.

Open
#23,217 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I've been trying to reproduce and minimize an auto-complete and semantic highlighting slowdown in our closed-source codebase. It's a rather large async method spanning over 500 lines of code. I've figured that the number of expressions (including the 20x tracing::debug!() lines) and it being async might be the reason why.

This Python script produces the repro code:

python3 - <<'EOF'
n = 1600
body = "".join(f"    let s{i} = String::new();\n    let l{i} = s{i}.len();\n"
               for i in range(n))
open("repro.rs", "w").write(
    f"pub fn sync_body() {{\n{body}}}\n"
    f"pub async fn async_body() {{\n{body}}}\n")
EOF

This produces a file that looks like:

pub fn sync_body() {
    let s0 = String::new();
    let l0 = s0.len();
    let s1 = String::new();
    let l1 = s1.len();
    // ...
    // s0.<|>
    // s0<|>
} 
pub async fn async_body() {
    let s0 = String::new();
    let l0 = s0.len();
    let s1 = String::new();
    let l1 = s1.len();
    // ...
    // s0.<|>
    // s0<|>
} 

Auto-complete in sync_body completes in roughly 1–2s. The async variant completes in roughly 5–6s.

Using rust-analyzer: d2e55da49132fa70a13dfbdc99122432b02cf464

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

Start by running the provided Python heredoc to generate repro.rs, then compare completion and semantic-highlighting behavior for sync_body and async_body at rust-analyzer commit d2e55da49132fa70a13dfbdc99122432b02cf464. Profile or trace the two cases to identify why the async version is slower. Done means the repro no longer shows the reported slowdown without regressing the sync case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
developer-experience, devtools, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.