Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extremely slow startup performance on Windows 10 due to Command::output #18753

Open
ZakisM opened this issue Dec 24, 2024 · 1 comment
Open
Labels
C-support Category: support questions

Comments

@ZakisM
Copy link

ZakisM commented Dec 24, 2024

rust-analyzer version: rust-analyzer 0.0.0 (c679648 2024-12-24)

rustc version:
rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-pc-windows-msvc
release: 1.83.0
LLVM version: 19.1.1

editor or extension: N/A

relevant settings: Windows 10 Version 22H2 (OS Build 19045.5247)

repository link (if public, optional): (eg. rust-analyzer)

code snippet to reproduce:

rust-analyzer analysis-stats .

I noticed that rust-analyzer was extremely slow to start for a brand new project (cargo new empty_project) due to the Database loaded metadata step:

Database loaded: 9.57s, 14mb (metadata 9.29s, 380kb; build 64.65ms, 0b)

After some analysis I added some extra logging to this function:

fn utf8_stdout(mut cmd: Command) -> anyhow::Result<String> {
    let time = std::time::Instant::now();
    let output = cmd.output().with_context(|| format!("{cmd:?} failed"))?;
    eprintln!("[Duration {}ms]/[Current Dir {:?}] - {cmd:?}", time.elapsed().as_millis(), cmd.get_current_dir());
    if !output.status.success() {
        match String::from_utf8(output.stderr) {
            Ok(stderr) if !stderr.is_empty() => {
                bail!("{:?} failed, {}\nstderr:\n{}", cmd, output.status, stderr)
            }
            _ => bail!("{:?} failed, {}", cmd, output.status),
        }
    }
    let stdout = String::from_utf8(output.stdout)?;
    Ok(stdout.trim().to_owned())
}

Running analysis-stats with this extra logging enabled:

❯ rust-analyzer analysis-stats .
[Duration 2127ms]/[Current Dir Some("C:\\Users\\zakmi\\RustroverProjects\\empty_project")] - "C:\\Users\\zakmi\\.cargo\\bin\\rustc.exe" "--print" "sysroot"
[Duration 2210ms]/[Current Dir Some("C:\\Users\\zakmi\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib/rustlib/src/rust/library")] - "C:\\Users\\zakmi\\.cargo\\bin\\cargo.exe" "-Z" "unstable-options" "config" "get" "build.target"
[Duration 2231ms]/[Current Dir Some("C:\\Users\\zakmi\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib/rustlib/src/rust/library")] - "C:\\Users\\zakmi\\.cargo\\bin\\rustc.exe" "-vV"
[Duration 43ms]/[Current Dir Some("C:\\Users\\zakmi\\RustroverProjects\\empty_project")] - "C:\\Users\\zakmi\\.cargo\\bin\\cargo.exe" "--version"
[Duration 70ms]/[Current Dir Some("C:\\Users\\zakmi\\RustroverProjects\\empty_project")] - "C:\\Users\\zakmi\\.cargo\\bin\\cargo.exe" "rustc" "-Z" "unstable-options" "--print" "cfg"
[Duration 64ms]/[Current Dir Some("C:\\Users\\zakmi\\RustroverProjects\\empty_project")] - "C:\\Users\\zakmi\\.cargo\\bin\\cargo.exe" "rustc" "-Z" "unstable-options" "--print" "target-spec-json" "--" "-Z" "unstable-options"
[Duration 53ms]/[Current Dir Some("C:\\Users\\zakmi\\RustroverProjects\\empty_project")] - "C:\\Users\\zakmi\\.cargo\\bin\\cargo.exe" "-Z" "unstable-options" "config" "get" "build.target"
[Duration 14ms]/[Current Dir Some("C:\\Users\\zakmi\\RustroverProjects\\empty_project")] - "C:\\Users\\zakmi\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\bin\\rustc.exe" "-vV"
[Duration 52ms]/[Current Dir Some("C:\\Users\\zakmi\\RustroverProjects\\empty_project")] - "C:\\Users\\zakmi\\.cargo\\bin\\cargo.exe" "-Z" "unstable-options" "config" "get" "env"
Database loaded:     9.57s, 14mb (metadata 9.29s, 380kb; build 64.65ms, 0b)
  item trees: 1
Item Tree Collection: 240.40µs, 0b
  crates: 1, mods: 1, decls: 1, bodies: 1, adts: 0, consts: 0
Item Collection:     3.36s, 200mb
Body lowering:       363.42ms, 53mb
  exprs: 16, ??ty: 0 (0%), ?ty: 0 (0%), !ty: 0
  pats: 0, ??ty: 0 (100%), ?ty: 0 (100%), !ty: 0
Inference:           142.44ms, 19mb
MIR lowering:        514.80µs, 0b
Mir failed bodies: 0 (0%)
Data layouts:        100.00ns, 0b
Failed data layouts: 0 (100%)
Const evaluation:    100.00ns, 0b
Failed const evals: 0 (100%)
Total:               3.87s, 272mb

Commands like C:\Users\zakmi\.cargo\bin\rustc.exe --print sysroot take around 2 seconds, where as running them directly through the terminal take ~70ms:

❯ Measure-Command { C:\Users\zakmi\.cargo\bin\rustc.exe --print sysroot }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 77
Ticks             : 779167
TotalDays         : 9.01813657407407E-07
TotalHours        : 2.16435277777778E-05
TotalMinutes      : 0.00129861166666667
TotalSeconds      : 0.0779167
TotalMilliseconds : 77.9167

This causes rust-analyzer performance to be very poor, especially on startup.

@ZakisM ZakisM added the C-bug Category: bug label Dec 24, 2024
@Veykril
Copy link
Member

Veykril commented Dec 24, 2024

That seems odd, I get


[Duration 60ms]/[Current Dir Some("C:\\workspace\\rust\\rust-analyzer")] - "C:\\Users\\lukas\\.cargo\\bin\\rustc.exe" "--print" "sysroot"
[Duration 17ms]/[Current Dir Some("C:\\Users\\lukas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib/rustlib/src/rust/library")] - "\\\\?\\C:\\Users\\lukas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\bin\\cargo.exe" "-Z" "unstable-opt
ions" "config" "get" "build.target"
[Duration 58ms]/[Current Dir Some("C:\\Users\\lukas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib/rustlib/src/rust/library")] - "C:\\Users\\lukas\\.cargo\\bin\\rustc.exe" "-vV"
[Duration 24ms]/[Current Dir Some("C:\\workspace\\rust\\rust-analyzer")] - "C:\\Users\\lukas\\.cargo\\bin\\cargo.exe" "--version"
[Duration 105ms]/[Current Dir Some("C:\\workspace\\rust\\rust-analyzer")] - "C:\\Users\\lukas\\.cargo\\bin\\cargo.exe" "rustc" "-Z" "unstable-options" "--print" "cfg"
[Duration 66ms]/[Current Dir Some("C:\\workspace\\rust\\rust-analyzer")] - "C:\\Users\\lukas\\.cargo\\bin\\cargo.exe" "rustc" "-Z" "unstable-options" "--print" "target-spec-json" "--" "-Z" "unstable-options"
[Duration 25ms]/[Current Dir Some("C:\\workspace\\rust\\rust-analyzer")] - "C:\\Users\\lukas\\.cargo\\bin\\cargo.exe" "-Z" "unstable-options" "config" "get" "build.target"
[Duration 11ms]/[Current Dir Some("C:\\workspace\\rust\\rust-analyzer")] - "C:\\Users\\lukas\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\bin\\rustc.exe" "-vV"
[Duration 26ms]/[Current Dir Some("C:\\workspace\\rust\\rust-analyzer")] - "C:\\Users\\lukas\\.cargo\\bin\\cargo.exe" "-Z" "unstable-options" "config" "get" "env"

There might be something fishy going on on your system?

@Veykril Veykril added C-support Category: support questions and removed C-bug Category: bug labels Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-support Category: support questions
Projects
None yet
Development

No branches or pull requests

2 participants