Skip to content

RA uses 14.7GB RAM on my M3 mac #19552

Not planned
Not planned
@undenuicap

Description

@undenuicap
Image

rust 1.85
fairly large project

what can be done here ? that is an insane amount of RAM.

Activity

davidbarsky

davidbarsky commented on Apr 9, 2025

@davidbarsky
Contributor

In terms of what could be immediately be done, disabling cache priming ("indexing") could help, but that largely defers the memory usage growth: if you're to open/visit the files in question, you'll largely end up with similar memory usage. This does mean the initial LSP requests will take longer, but if you have a large Cargo workspace but rarely touch some crates, this might help.

Out of curiosity, how many lines of code this is project? We've had reports of rust-analyzer's memory usage increasing dramatically on some projects since #18964 landed, but we haven't really determined why some projects seem to have large memory usage spikes while others simply don't.

undenuicap

undenuicap commented on Apr 9, 2025

@undenuicap
Author

what I meant is what can you do to fix this issue - which is obviously a bug. Cant you use some memory mapped storage and map a smaller amount of it to RAM than 14GB ? something is wrong with how you store those structs in memory.

davidbarsky

davidbarsky commented on Apr 9, 2025

@davidbarsky
Contributor

something is wrong with how you store those structs in memory.

Well, yes: the trouble is that it's not clear to us what exactly is wrong. Do you mind cloning and building rust-analyzer from source using cargo xtask install --server --jemalloc --dev-rel and run ~/.cargo/bin/rust-analyzer analysis-stats . in the root of your Cargo workspace? Sharing that output would help us better diagnose what is going wrong.

Rudxain

Rudxain commented on Apr 16, 2025

@Rudxain

Just for reference: #19402

jkelleyrtp

jkelleyrtp commented on Apr 17, 2025

@jkelleyrtp
Contributor

Hi - running into similar issues on the http://github.com/dioxusLabs/dioxus/ repo. 17gb of memory usage and seems to endlessly climb.

This is particularly bad on my machine because I only have 32gb of ram and rust-analyzer and cargo check truly chug (6+ sec per check), assuming it's paging in memory from swap. It got so bad I just bought an M4 with 128gb of ram, coming in tomorrow :-)

Image

Lines:

❯ tokei
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 Batch                   1           90           68            0           22
 CSS                    31         3542         2606          365          571
 D                       1            1            1            0            0
 Handlebars              6          179          157            0           22
 JavaScript             33         1306          826          295          185
 JSON                   11         6806         6806            0            0
 Kotlin                  1           22           19            0            3
 Nix                     1           69           57            7            5
 Prolog                  1           21           18            0            3
 Shell                   3          281          164           73           44
 SVG                     7          120          120            0            0
 Plain Text              7        38923            0        38812          111
 TOML                   86         3411         2732          228          451
 TypeScript             15         1866         1415          197          254
 XML                     5          218          215            2            1
 YAML                    1            2            2            0            0
-------------------------------------------------------------------------------
 HTML                    7          281          269            7            5
 |- CSS                  2          320          252            9           59
 |- HTML                 1           24           18            6            0
 |- JavaScript           5          105           65           24           16
 (Total)                            730          604           46           80
-------------------------------------------------------------------------------
 Markdown               72         4994            0         3478         1516
 |- BASH                 3            5            5            0            0
 |- Rust                40         2934         2394          279          261
 |- Shell                4           20           13            4            3
 |- TOML                 4           23           19            1            3
 (Total)                           7976         2431         3762         1783
-------------------------------------------------------------------------------
 Rust                  604        96319        77942         5601        12776
 |- Markdown           418        14226         3470         8683         2073
 (Total)                         110545        81412        14284        14849
===============================================================================
 Total                 893       158451        93417        49065        15969
===============================================================================

analysis-stats:

Database loaded:     119.10s, 366mb (metadata 1.40s, 5mb; build 115.63s, -168kb)
item trees: 605
  dependency lines of code: 8_556_576, item trees: 21_142
  dependency item stats: traits: 5_079, impl: 107_917, mods: 26_087, macro calls: 30_054, macro rules: 5_882
Item Tree Collection: 13.59s, 2735mb
  Total Statistics:
    crates: 254, mods: 1096, decls: 12587, bodies: 10502, adts: 1347, consts: 1977
  Workspace:
    traits: 379, macro_rules macros: 9, proc_macros: 19
    lines of code: 111_996, item trees: 605
    usages: traits: 89, impl: 1_308, mods: 401, macro calls: 112, macro rules: 35
  Dependencies:
    lines of code: 8_556_576, item trees: 21_142
    declarations: traits: 5_079, impl: 107_917, mods: 26_087, macro calls: 30_054, macro rules: 5_882
Item Collection:     47.41s, 5663mb
Body lowering:       3.81s, 626mb                                                                                                      
  exprs: 428340, ??ty: 2315 (0%), ?ty: 657 (0%), !ty: 6                                                                                
  pats: 61390, ??ty: 160 (0%), ?ty: 63 (0%), !ty: 0
Inference:           43.99s, 4131mb
MIR lowering:        11.68s, 317mb
Mir failed bodies: 452 (4%)
Data layouts:        128.04ms, 20mb
Failed data layouts: 4 (0%)
Const evaluation:    38.84ms, 5mb
Failed const evals: 75 (3%)
Total:               125.88s, 6398mb

With --run-all-ide-things:

❯ ~/.cargo/bin/rust-analyzer analysis-stats . --run-all-ide-things
Database loaded:     6.42s, 367mb (metadata 1.42s, 5mb; build 3.90s, -135kb)
^[[O  item trees: 605
  dependency lines of code: 8_556_576, item trees: 21_142
  dependency item stats: traits: 5_079, impl: 107_917, mods: 26_087, macro calls: 30_054, macro rules: 5_882
Item Tree Collection: 12.94s, 2735mb
  Total Statistics:
    crates: 254, mods: 1096, decls: 12587, bodies: 10502, adts: 1347, consts: 1977
  Workspace:
    traits: 379, macro_rules macros: 9, proc_macros: 19
    lines of code: 111_996, item trees: 605
    usages: traits: 89, impl: 1_308, mods: 401, macro calls: 112, macro rules: 35
  Dependencies:
    lines of code: 8_556_576, item trees: 21_142
    declarations: traits: 5_079, impl: 107_917, mods: 26_087, macro calls: 30_054, macro rules: 5_882
Item Collection:     52.78s, 5666mb
Body lowering:       3.87s, 627mb                                                                                                      
  exprs: 428340, ??ty: 2315 (0%), ?ty: 657 (0%), !ty: 6                                                                                
  pats: 61390, ??ty: 160 (0%), ?ty: 63 (0%), !ty: 0
Inference:           43.87s, 4131mb
MIR lowering:        11.94s, 317mb
Mir failed bodies: 452 (4%)
Data layouts:        141.36ms, 20mb
Failed data layouts: 4 (0%)
Const evaluation:    45.40ms, 5mb
Failed const evals: 75 (3%)

// after commenting out the bad never! - here's the results.
IDE:                 55.98s, 867mb (593 files)
Total:               187.50s, 7140mb

thread 'main' panicked at crates/ide/src/inlay_hints.rs:320:13:
inlay hint produced an empty text edit
stack backtrace:
   0: rust_begin_unwind
             at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panicking.rs:695:5
   1: core::panicking::panic_fmt
             at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/core/src/panicking.rs:75:14
   2: ide::inlay_hints::InlayHintsConfig::lazy_text_edit
             at /Users/jonkelley/Development/Tinkering/rust-analyzer/crates/ide/src/inlay_hints.rs:320:13
   3: ide::inlay_hints::closure_ret::hints
             at /Users/jonkelley/Development/Tinkering/rust-analyzer/crates/ide/src/inlay_hints/closure_ret.rs:65:14
   4: ide::inlay_hints::hints
             at /Users/jonkelley/Development/Tinkering/rust-analyzer/crates/ide/src/inlay_hints.rs:236:25
   5: ide::inlay_hints::inlay_hints::{{closure}}
             at /Users/jonkelley/Development/Tinkering/rust-analyzer/crates/ide/src/inlay_hints.rs:105:13
   6: ide::inlay_hints::inlay_hints
             at /Users/jonkelley/Development/Tinkering/rust-analyzer/crates/ide/src/inlay_hints.rs:116:9
   7: ide::Analysis::inlay_hints::{{closure}}
             at /Users/jonkelley/Development/Tinkering/rust-analyzer/crates/ide/src/lib.rs:460:27
   8: ide::Analysis::with_db::{{closure}}
             at /Users/jonkelley/Development/Tinkering/rust-analyzer/crates/ide/src/lib.rs:870:29
   9: std::panicking::try::do_call
             at /Users/jonkelley/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:587:40
  10: std::panicking::try
             at /Users/jonkelley/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:550:19
  11: std::panic::catch_unwind
             at /Users/jonkelley/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/panic.rs:358:14
  12: salsa::cancelled::Cancelled::catch
             at /Users/jonkelley/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/salsa-0.19.0/src/cancelled.rs:36:15
  13: ide::Analysis::with_db
             at /Users/jonkelley/Development/Tinkering/rust-analyzer/crates/ide/src/lib.rs:870:9
  14: ide::Analysis::inlay_hints
             at /Users/jonkelley/Development/Tinkering/rust-analyzer/crates/ide/src/lib.rs:460:9
  15: rust_analyzer::cli::analysis_stats::<impl rust_analyzer::cli::flags::AnalysisStats>::run_ide_things
             at /Users/jonkelley/Development/Tinkering/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs:1130:17
  16: rust_analyzer::cli::analysis_stats::<impl rust_analyzer::cli::flags::AnalysisStats>::run
             at /Users/jonkelley/Development/Tinkering/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs:334:13
  17: rust_analyzer::actual_main
             at /Users/jonkelley/Development/Tinkering/rust-analyzer/crates/rust-analyzer/src/bin/main.rs:80:55
  18: rust_analyzer::main
             at /Users/jonkelley/Development/Tinkering/rust-analyzer/crates/rust-analyzer/src/bin/main.rs:38:9
  19: core::ops::function::FnOnce::call_once
             at /Users/jonkelley/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

my config:

"rust-analyzer.cargo.buildScripts.rebuildOnSave": false,
  "rust-analyzer.check.workspace": false,
  "rust-analyzer.procMacro.attributes.enable": true,
  "rust-analyzer.diagnostics.disabled": [
    "macro-error",
    "unresolved-proc-macro"
  ],
  "rust-analyzer.completion.privateEditable.enable": false,
  "rust-analyzer.inlayHints.renderColons": true,
  "rust-analyzer.inlayHints.parameterHints.enable": true,
  "rust-analyzer.completion.fullFunctionSignatures.enable": false,
  "rust-analyzer.imports.preferPrelude": true,
  "rust-analyzer.inlayHints.closureReturnTypeHints.enable": "with_block",
  "rust-analyzer.inlayHints.closureStyle": "rust_analyzer",
  "rust-analyzer.imports.granularity.enforce": true,
  "rust-analyzer.inlayHints.lifetimeElisionHints.enable": "skip_trivial",
  "rust-analyzer.inlayHints.typeHints.enable": true,
  "rust-analyzer.lens.references.adt.enable": true,
  "rust-analyzer.lens.references.method.enable": false,
  "rust-analyzer.lens.references.trait.enable": true,
  "rust-analyzer.lens.references.enumVariant.enable": false,
  "rust-analyzer.restartServerOnConfigChange": true,
  "rust-analyzer.cargo.buildScripts.enable": false,
  "rust-analyzer.check.allTargets": false,
  "rust-analyzer.cachePriming.enable": false,
  "rust-analyzer.cargo.extraArgs": [
    "--profile",
    "ra-fast"
  ],
undenuicap

undenuicap commented on May 16, 2025

@undenuicap
Author

this is still happening. sometimes I end up with 3 rust analyser processes running, each occupying 15GB of RAM.

1 rust analyser process occupies double the RAM rust rover uses for the whole IDE.

will have to move back to RustRover. Such a shame.

Veykril

Veykril commented on May 16, 2025

@Veykril
Member

You are free to do so, no one is forcing you to use rust-analyzer, just know that comments like these do not help anyone. They do not fix these issues either, in fact they might have the opposite of effect! So you might want to reconsider these kinds of comments in the future.

locked and limited conversation to collaborators on May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @davidbarsky@Veykril@jkelleyrtp@Rudxain@undenuicap

        Issue actions

          RA uses 14.7GB RAM on my M3 mac · Issue #19552 · rust-lang/rust-analyzer