rust-lang / rust-lang/rust-analyzer
Slow auto-complete / semantic highlighting with async function and lots of expressions.
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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