rust-lang / rust-lang/rust-analyzer

enabled a lens config CodeAction is very slow

Open
#17,950 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

rust-analyzer version: rust-analyzer 1.82.0-nightly (7c2012d0 2024-07-26)

rustc version: rustc 1.82.0-nightly (7c2012d0e 2024-07-26)

editor or extension: Vim 9.1 coc-rust-analyzer

relevant settings:

{
    "rust-analyzer.updates.checkOnStartup": false,
    "rust-analyzer.lens.references.method.enable": true
}

code snippet to reproduce src/main.rs:

use std::{fmt::Display, ops::Deref};

#[derive(Debug, Clone, Eq)]
pub enum ParseLine<'a> {
    Label(&'a str),
    Args((), u32),
}
impl<'a> PartialEq for ParseLine<'a> {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (Self::Label(l0), Self::Label(r0)) => l0 == r0,
            (Self::Args(l0, _), Self::Args(r0, _)) => l0 == r0,
            _ => false,
        }
    }
}
impl<'a> TryFrom<Vec<&'a str>> for ParseLine<'a> {
    type Error = ();

    fn try_from(_: Vec<&'a str>) -> Result<Self, Self::Error> {
        Ok(Self::Args((), 0))
    }
}
impl<'a> From<&'a str> for ParseLine<'a> {
    fn from(_: &'a str) -> Self {
        todo!()
    }
}
impl<'a> From<()> for ParseLine<'a> {
    fn from(_: ()) -> Self {
        todo!()
    }
}
impl<'a> Display for ParseLine<'a> {
    fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        todo!()
    }
}


fn main() { }

reproduce steps:

  1. open file src/main.rs, CPU Usage to 400%, Memory Usage to 851 MB
  2. in line 11 => l0 start CodeAction, is slow
  3. any edit and save file, and start CodeAction is very slow, Max CPU Usage to 700%, Memory Usage to 1350 MB

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 with the reproduction in src/main.rs, especially the CodeAction at line 11 and the reported rust-analyzer settings. Reproduce the action before and after editing and saving, then investigate the excessive CPU and memory usage. Done means the CodeAction no longer becomes very slow or reaches the reported resource usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, vim
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.