rust-lang / rust-lang/rust-analyzer

Add return type very slow

Open
#20,924 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

rust-analyzer version: rust-analyzer 0.4.2655-standalone

rustc version: rustc 1.91.0-nightly (040a98af7 2025-08-20)

editor or extension: Vim9.1 coc-rust-analyzer

code snippet to reproduce:

file rust-analyzer/crates/ide-assists/src/handlers/foo.rs:

use syntax::{
    AstToken
};

use crate::assist_context::{AssistContext, Assists};

pub(crate) fn foo(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
    let x = split_curly("", 2)?;
    Some(())
}

fn split_curly(text: &str, offset: usize) -> $0 {
    Some("")
}

and add mod foo; to mod handlers rust-analyzer/crates/ide-assists/src/lib.rs
and add foo::foo to fn all() from rust-analyzer/crates/ide-assists/src/lib.rs

file coc-settings.json:

{
    "rust-analyzer.updates.checkOnStartup": false,
    "rust-analyzer.check.workspace": false,
    "rust-analyzer.cachePriming.enable": false
}

Change work dir to rust-analyzer/crates/ide-assists

Run vim src/handlers/foo.rs

Click code-action at $0 very slow (used 100% CPU and experiencing memory growth)

And the memory used during startup is more than twice as much as before

It seems that there is no such issue on version 2025-08-25

@rustbot label +A-perf

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

Reproduce the report from rust-analyzer/crates/ide-assists/src/handlers/foo.rs and the mod handlers/all() entries in rust-analyzer/crates/ide-assists/src/lib.rs, using the stated coc-rust-analyzer settings and Vim code action. Compare behavior with the reported 2025-08-25 version, then trace the add-return-type action. Done means the reproduction no longer causes excessive CPU or memory growth.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.