rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.39k stars 1.62k forks source link

Memory leak: rust-analyzer eat up 8GB of RAM too quickly #8749

Closed KSXGitHub closed 3 years ago

KSXGitHub commented 3 years ago

System Information

Steps to reproduce

  1. Clone https://github.com/KSXGitHub/dirt.git
  2. Checkout commit 1be5539b98fd229f438ce90af7660db1c61fae8d.
  3. Open the project in Visual Studio Code.
  4. Go to file src/visualizer/test.rs.
  5. Wait for a minute or two.

You should see that if rust-analyzer crashing and eating up memory.

I also tried Sublime Text 3 with LSP and Rust Enhanced extension, it does not eat up all memory, but it still crashes.

Veykril commented 3 years ago

What version of Rust-Analyzer is this occuring on?

KSXGitHub commented 3 years ago

@Veykril I have edited the issue to include versions of the rust-analyzer binary package and VS Code extension.

matklad commented 3 years ago

Reproduced

12:27:11|~/projects
λ git clone https://github.com/KSXGitHub/dirt.git && cd dirt && git switch --detach 1be5539b98fd229f438ce90af7660db1c61fae8d
Cloning into 'dirt'...
remote: Enumerating objects: 1156, done.
remote: Counting objects: 100% (46/46), done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 1156 (delta 29), reused 36 (delta 21), pack-reused 1110
Receiving objects: 100% (1156/1156), 160.89 KiB | 1.23 MiB/s, done.
Resolving deltas: 100% (787/787), done.
HEAD is now at 1be5539 test: Parenthood and ChildPosition is correctly re-assigned

12:27:30|~/projects/dirt|HEAD✓
λ rust-analyzer --version
rust-analyzer 53f7149d4 2021-05-07 dev

12:27:37|~/projects/dirt|HEAD✓
λ rust-analyzer analysis-stats .
Database loaded:     606.90ms, 135minstr
  crates: 4, mods: 37, decls: 243, fns: 141
Item Collection:     2.78s, 30ginstr
20/141 14% processing: visualizer::test::big_tree_with_long_names_short_max_width     

cc flodiebold

Oh, that actually failed lovely, cc @edwin0cheng :-)

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: TryFromIntError(())', crates/syntax/src/parsing/lexer.rs:107:76
stack backtrace:
   0: rust_begin_unwind
             at /rustc/88f19c6dab716c6281af7602e30f413e809c5974/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/88f19c6dab716c6281af7602e30f413e809c5974/library/core/src/panicking.rs:92:14
   2: core::option::expect_none_failed
             at /rustc/88f19c6dab716c6281af7602e30f413e809c5974/library/core/src/option.rs:1329:5
   3: syntax::parsing::lexer::lex_single_syntax_kind
   4: mbe::subtree_source::SubtreeTokenSource::new
   5: mbe::syntax_bridge::token_tree_to_syntax_node
   6: <hir_expand::db::ParseMacroExpansionQuery as salsa::plumbing::QueryFunction>::execute
   7: salsa::runtime::Runtime::execute_query_implementation
   8: salsa::derived::slot::Slot<Q,MP>::read_upgrade
   9: salsa::derived::slot::Slot<Q,MP>::read
  10: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  11: <DB as hir_expand::db::AstDatabase>::parse_macro_expansion::__shim
  12: <DB as hir_expand::db::AstDatabase>::parse_macro_expansion
  13: hir_expand::db::parse_or_expand
  14: hir_expand::eager::eager_macro_recur
  15: hir_expand::eager::eager_macro_recur
  16: hir_expand::eager::expand_eager_macro
  17: hir_expand::eager::eager_macro_recur
  18: hir_expand::eager::eager_macro_recur
  19: hir_expand::eager::expand_eager_macro
  20: hir_expand::eager::eager_macro_recur
  21: hir_expand::eager::eager_macro_recur
  22: hir_expand::eager::expand_eager_macro
  23: hir_expand::eager::eager_macro_recur
  24: hir_expand::eager::eager_macro_recur
  25: hir_expand::eager::expand_eager_macro
  26: hir_expand::eager::eager_macro_recur
  27: hir_expand::eager::eager_macro_recur
  28: hir_expand::eager::expand_eager_macro
  29: hir_expand::eager::eager_macro_recur
  30: hir_expand::eager::eager_macro_recur
  31: hir_expand::eager::expand_eager_macro
  32: hir_expand::eager::eager_macro_recur
  33: hir_expand::eager::eager_macro_recur
  34: hir_expand::eager::expand_eager_macro
  35: hir_expand::eager::eager_macro_recur
  36: hir_expand::eager::eager_macro_recur
  37: hir_expand::eager::expand_eager_macro
  38: hir_expand::eager::eager_macro_recur
  39: hir_expand::eager::eager_macro_recur
  40: hir_expand::eager::expand_eager_macro
  41: hir_expand::eager::eager_macro_recur
  42: hir_expand::eager::eager_macro_recur
  43: hir_expand::eager::expand_eager_macro
  44: hir_expand::eager::eager_macro_recur
  45: hir_expand::eager::eager_macro_recur
  46: hir_expand::eager::expand_eager_macro
  47: hir_expand::eager::eager_macro_recur
  48: hir_expand::eager::eager_macro_recur
  49: hir_expand::eager::expand_eager_macro
  50: hir_expand::eager::eager_macro_recur
  51: hir_expand::eager::eager_macro_recur
  52: hir_expand::eager::expand_eager_macro
  53: hir_expand::eager::eager_macro_recur
  54: hir_expand::eager::eager_macro_recur
  55: hir_expand::eager::expand_eager_macro
  56: hir_expand::eager::eager_macro_recur
  57: hir_expand::eager::eager_macro_recur
  58: hir_expand::eager::expand_eager_macro
  59: hir_expand::eager::eager_macro_recur
  60: hir_expand::eager::eager_macro_recur
  61: hir_expand::eager::expand_eager_macro
  62: hir_expand::eager::eager_macro_recur
  63: hir_expand::eager::eager_macro_recur
  64: hir_expand::eager::expand_eager_macro
  65: hir_expand::eager::eager_macro_recur
  66: hir_expand::eager::eager_macro_recur
  67: hir_expand::eager::expand_eager_macro
  68: hir_expand::eager::eager_macro_recur
  69: hir_expand::eager::eager_macro_recur
  70: hir_expand::eager::expand_eager_macro
  71: hir_expand::eager::eager_macro_recur
  72: hir_expand::eager::eager_macro_recur
  73: hir_expand::eager::expand_eager_macro
  74: hir_expand::eager::eager_macro_recur
  75: hir_expand::eager::eager_macro_recur
  76: hir_expand::eager::expand_eager_macro
  77: hir_expand::eager::eager_macro_recur
  78: hir_expand::eager::eager_macro_recur
  79: hir_expand::eager::expand_eager_macro
  80: hir_expand::eager::eager_macro_recur
  81: hir_expand::eager::eager_macro_recur
  82: hir_expand::eager::expand_eager_macro
  83: hir_expand::eager::eager_macro_recur
  84: hir_expand::eager::eager_macro_recur
  85: hir_expand::eager::expand_eager_macro
  86: hir_expand::eager::eager_macro_recur
  87: hir_expand::eager::eager_macro_recur
  88: hir_expand::eager::expand_eager_macro
  89: hir_expand::eager::eager_macro_recur
  90: hir_expand::eager::eager_macro_recur
  91: hir_expand::eager::expand_eager_macro
  92: hir_expand::eager::eager_macro_recur
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
matklad commented 3 years ago

Oh my, what failed is usize to TextSize conversion :rofl: Nothing too see here, just a STRING of 6_496_284_431 bytes

edwin0cheng commented 3 years ago

MWE:

macro_rules! text_block {
    () => {
        ""
    };

    ($line:literal) => {
        $line
    };

    ($head:literal $($tail:literal)*) => {
        ::std::concat!($head, "\n", $crate::text_block!($($tail)*))
    };
}

fn main() {
    let _ = text_block! {
        "999B     ┌──first ...│                       ░░░░░░░░░░░│  0%"
        "750B     │ ┌──b      │                       ░░░░░░░▒▒▒▒│  0%"
        "750B     │ ├──a      │                       ░░░░░░░▒▒▒▒│  0%"
        "123B     │ │ ┌──abc  │                       ░░░░░░░▒▒▒▓│  0%"
        "456B     │ │ ├──def  │                       ░░░░░░░▒▒▒▓│  0%"
        "750B     │ │ ├──c    │                       ░░░░░░░▒▒▒▓│  0%"
        "  5K     │ ├─┴firs...│                       ░░░░░░░▒▒▒█│  2%"
        "  8K     │ ├──seco...│                       ░░░░░░░▒▒▒█│  3%"
        "750B     │ │ ┌──f    │                       ░░░░░░░▒▒▓▓│  0%"
        "750B     │ │ ├──e    │                       ░░░░░░░▒▒▓▓│  0%"
        "750B     │ │ ├──d    │                       ░░░░░░░▒▒▓▓│  0%"
        "  1K     │ │ ├──ab...│                       ░░░░░░░▒▒▓▓│  0%"
        "  1K     │ │ ├──ab...│                       ░░░░░░░▒▒▓▓│  0%"
        "  4K     │ │ ├──ih...│                       ░░░░░░░▒▒▓█│  1%"
        "  4K     │ │ ├──th...│                       ░░░░░░░▒▒▓█│  2%"
        " 17K     │ ├─┴seco...│                       ░░░░░░░▒▒██│  6%"
        " 36K     ├─┴sub 1.1  │                       ░░░░░░░████│ 12%"
        "750B     │ ┌──g      │                       ░░░░░▒▒▒▒▒▒│  0%"
        "750B     │ │ ┌──j    │                       ░░░░░▒▒▒▒▒▓│  0%"
        "750B     │ │ ├──i    │                       ░░░░░▒▒▒▒▒▓│  0%"
        "750B     │ │ │ ┌──m  │                       ░░░░░▒▒▒▒▒▓│  0%"
        "750B     │ │ │ ├──l  │                       ░░░░░▒▒▒▒▒▓│  0%"
        "750B     │ │ │ ├──k  │                       ░░░░░▒▒▒▒▒▓│  0%"
        "  7K     │ │ ├─┴si...│                       ░░░░░▒▒▒▒▒█│  2%"
        " 12K     │ ├─┴fift...│                       ░░░░░▒▒▒▒▒█│  4%"
        "750B     │ │   ┌──h  │                       ░░░░░▒▒▒▒▒▓│  0%"
        "  8K     │ │ ┌─┴fo...│                       ░░░░░▒▒▒▒▒█│  3%"
        " 12K     │ ├─┴thir...│                       ░░░░░▒▒▒▒▒█│  4%"
        "750B     │ │ ┌──n    │                       ░░░░░▒▒▒▓▓▓│  0%"
        "777B     │ │ ├──ni...│                       ░░░░░▒▒▒▓▓▓│  0%"
        "750B     │ │ │ ┌──r  │                       ░░░░░▒▒▒▓▓▓│  0%"
        "750B     │ │ │ ├──q  │                       ░░░░░▒▒▒▓▓▓│  0%"
        "750B     │ │ │ ├──p  │                       ░░░░░▒▒▒▓▓▓│  0%"
        "  7K     │ │ ├─┴ei...│                       ░░░░░▒▒▒▓▓█│  2%"
        "750B     │ │ │ ┌──o  │                       ░░░░░▒▒▒▓▓▓│  0%"
        " 12K     │ │ ├─┴se...│                       ░░░░░▒▒▒▓▓█│  4%"
        " 24K     │ ├─┴sixt...│                       ░░░░░▒▒▒███│  8%"
        " 53K     ├─┴sub 1.2  │                       ░░░░░██████│ 18%"
        " 93K   ┌─┴sub 1      │                       ███████████│ 32%"
        "750B   │   ┌──y      │            ░░░░░░░░░░░░░░░░░▒▒▒▒▒│  0%"
        "352B   │   │ ┌──th...│            ░░░░░░░░░░░░░░░░░▒▒▒▓▓│  0%"
        "453B   │   │ ├──tw...│            ░░░░░░░░░░░░░░░░░▒▒▒▓▓│  0%"
        "750B   │   │ ├──z    │            ░░░░░░░░░░░░░░░░░▒▒▒▓▓│  0%"
        "750B   │   │ │ ┌──A  │            ░░░░░░░░░░░░░░░░░▒▒▒▓▓│  0%"
        "  5K   │   │ ├─┴tw...│            ░░░░░░░░░░░░░░░░░▒▒▒▓█│  2%"
        "750B   │   │ │ ┌──B  │            ░░░░░░░░░░░░░░░░░▒▒▒▓▓│  0%"
        "  6K   │   │ ├─┴th...│            ░░░░░░░░░░░░░░░░░▒▒▒▓█│  2%"
        " 16K   │   ├─┴elev...│            ░░░░░░░░░░░░░░░░░▒▒▒██│  6%"
        "357B   │   │ ┌──ei...│            ░░░░░░░░░░░░░░░░░▒▒▒▓▓│  0%"
        "542B   │   │ ├──ei...│            ░░░░░░░░░░░░░░░░░▒▒▒▓▓│  0%"
        "750B   │   │ ├──E    │            ░░░░░░░░░░░░░░░░░▒▒▒▓▓│  0%"
        "750B   │   │ ├──D    │            ░░░░░░░░░░░░░░░░░▒▒▒▓▓│  0%"
        "750B   │   │ ├──C    │            ░░░░░░░░░░░░░░░░░▒▒▒▓▓│  0%"
        "750B   │   │ │ ┌──G  │            ░░░░░░░░░░░░░░░░░▒▒▒▓▓│  0%"
        "750B   │   │ │ ├──F  │            ░░░░░░░░░░░░░░░░░▒▒▒▓▓│  0%"
        "  6K   │   │ ├─┴tw...│            ░░░░░░░░░░░░░░░░░▒▒▒▓█│  2%"
        "750B   │   │ │ ┌──H  │            ░░░░░░░░░░░░░░░░░▒▒▒▓▓│  0%"
        "  6K   │   │ ├─┴fi...│            ░░░░░░░░░░░░░░░░░▒▒▒▓█│  2%"
        " 19K   │   ├─┴four...│            ░░░░░░░░░░░░░░░░░▒▒▒██│  6%"
        " 39K   │ ┌─┴sub 2.2  │            ░░░░░░░░░░░░░░░░░█████│ 14%"
        "750B   │ │ ┌──s      │            ░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│  0%"
        "750B   │ │ │ ┌──u    │            ░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓│  0%"
        "750B   │ │ │ ├──t    │            ░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓│  0%"
        "750B   │ │ │ │ ┌──x  │            ░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓│  0%"
        "750B   │ │ │ │ ├──w  │            ░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓│  0%"
        "750B   │ │ │ │ ├──v  │            ░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓│  0%"
        " 50K   │ │ │ ├─┴te...│            ░░░░░▓▓▓▓▓▓▓▓▓▓▓██████│ 17%"
        " 87K   │ │ │ ├──te...│            ░░░░░▓▓▓▓▓▓▓██████████│ 30%"
        "142K   │ │ ├─┴nint...│            ░░░░░█████████████████│ 49%"
        "147K   │ ├─┴sub 2.1  │            ░░░░░█████████████████│ 51%"
        "190K   ├─┴sub 2      │            ██████████████████████│ 66%"
        "287K ┌─┴root         │██████████████████████████████████│100%"
    };
}