Skip to content

Infinite RAM usage #19551

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

Open
lelongg opened this issue Apr 9, 2025 · 7 comments
Open

Infinite RAM usage #19551

lelongg opened this issue Apr 9, 2025 · 7 comments
Labels
C-bug Category: bug

Comments

@lelongg
Copy link

lelongg commented Apr 9, 2025

I don't know if I should be opening an other issue for this since there is already several issues about RAM usage but I can't find a definitive answer.

Is this RAM usage an expected behavior of rust-analyzer or symptoms of a bug ?
The RAM usage seems to be growing through the day.

Image

Here is some information about the project size (it's a cargo workspace of ~100 crates).

===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 Rust                 1157       138605       127650          530        10425
 |- Markdown           112          701            5          623           73
 (Total)                         139306       127655         1153        10498
===============================================================================
 Total                1157       138605       127650          530        10425
===============================================================================

Installed version is 0.3.2370.

@lelongg lelongg added the C-bug Category: bug label Apr 9, 2025
@davidbarsky
Copy link
Contributor

Another issue is helpful, thanks. 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 only edit a small subset of crates, this could help a bit.

As for if we're treating this as a bug: we are. We've had reports of rust-analyzer's memory usage increasing dramatically on some projects since #18964 landed, but haven't determined why some projects experience the memory usage spike. Is the code in question open-source...?

@lelongg
Copy link
Author

lelongg commented Apr 9, 2025

Having read most of the threads about this issue, I've already disabled cachePriming on this project.

I cannot share code source but if you have specific questions about what could be special about our project, please ask.

@flodiebold
Copy link
Member

Can you run rust-analyzer analysis-stats . on the project and report the results?

@lelongg
Copy link
Author

lelongg commented Apr 9, 2025

I didn't find the path of the rust-analyzer binary used by the extension so I used rust-analyzer version 2025-02-24 and this is the output:

Database loaded:     47.69s, 8436minstr, 199mb (metadata 956.72ms, 55minstr, 7mb; build 44.58s, 50minstr, 379kb)
  item trees: 1185
Item Tree Collection: 655.05ms, 5895minstr, 28mb
  crates: 139, mods: 1972, decls: 41867, bodies: 37219, adts: 5249, consts: 3533
Item Collection:     90.58s, 632ginstr, 3268mb
Body lowering:       11.25s, 79ginstr, 431mb                                                                                                                                                               
  exprs: 1243598, ??ty: 583 (0%), ?ty: 204 (0%), !ty: 2068                                                                                                                                                 
  pats: 232679, ??ty: 39 (0%), ?ty: 28 (0%), !ty: 0
Inference:           203.43s, 1076ginstr, 2082mb
MIR lowering:        32.77s, 172ginstr, 465mb
Mir failed bodies: 2760 (8%)
Data layouts:        111.85ms, 637minstr, 14mb
Failed data layouts: 26 (0%)
Const evaluation:    117.89ms, 567minstr, 5mb
Failed const evals: 135 (3%)
Total:               338.99s, 1968ginstr, 6297mb

@davidbarsky
Copy link
Contributor

We've recently added some new functionality to rust-analyzer that provides more detail about what is being analyzed. If you're to clone and build rust-analyzer from source using cargo xtask install --server --jemalloc --dev-rel (latest stable is fine!) and rerun analysis-stats, it'll emit more information about the shape of your project. Do you mind doing that?

@lelongg
Copy link
Author

lelongg commented Apr 10, 2025

Here is the report with commit 432a3bc

Database loaded:     148.42s, 3313minstr, 694mb (metadata 2.59s, 1334kinstr, 6mb; build 143.94s, 81minstr, 30kb)
  item trees: 1184
  dependency lines of code: 18_462_466, item trees: 33_407
  dependency item stats: traits: 8_297, impl: 188_683, mods: 108_629, macro calls: 43_023, macro rules: 8_299
Item Tree Collection: 29.99s, 307ginstr, 5239mb
  Total Statistics:
    crates: 139, mods: 1970, decls: 41831, bodies: 37182, adts: 5246, consts: 3533
  Workspace:
    traits: 113, macro_rules macros: 29, proc_macros: 2
    lines of code: 218_310, item trees: 1_184
    usages: traits: 75, impl: 4_617, mods: 1_766, macro calls: 145, macro rules: 33
  Dependencies:
    lines of code: 18_462_466, item trees: 33_407
    declarations: traits: 8_297, impl: 188_683, mods: 108_629, macro calls: 43_023, macro rules: 8_299
Item Collection:     69.15s, 454ginstr, 8605mb
Body lowering:       7.31s, 59ginstr, 1055mb                                                                                                                                                               
  exprs: 1241663, ??ty: 613 (0%), ?ty: 196 (0%), !ty: 2068                                                                                                                                                 
  pats: 232323, ??ty: 39 (0%), ?ty: 28 (0%), !ty: 0
Inference:           207.93s, 1110ginstr, 4243mb
MIR lowering:        34.37s, 215ginstr, 658mb
Mir failed bodies: 2784 (8%)
Data layouts:        90.44ms, 331minstr, 19mb
Failed data layouts: 26 (0%)
Const evaluation:    90.82ms, 447minstr, 12mb
Failed const evals: 142 (4%)
Total:               352.95s, 2172ginstr, 8958mb

@Rudxain
Copy link

Rudxain commented Apr 16, 2025

Just for reference: #19402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants