rust-lang / rust-analyzer

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

Huge memory consumption and it continues growing #2052

Closed davyzhang closed 4 years ago

davyzhang commented 4 years ago

image image

matklad commented 4 years ago

In this form, the issue is not actionable: it is not a trivially reproducible problem (I don't think I've ever seen something quite like this myself), so there must be something special about your particular environment which makes rust-analyzer misbehave. At the same time, there are zero details about such environment.

@davyzhang could you provide a little more info about this:

Sorry for sounding a little cranky: I haven't had my first cup of pu'er yet :) But it is a little dispiriting to get an issue which describes a serious problem, without providing any means to debug it.

matklad commented 4 years ago

Hm, I thin I've reproduced this now actually! So looks like the crucial bit of info that was missing is that its a recent regression.

matklad commented 4 years ago

Looks like the chalk is to blame: https://gist.github.com/matklad/c6320c19b08afc8e6d8ca8612354d5b8

davyzhang commented 4 years ago

Sorry for the quick issue, I actually update, compile, and use analyzer every day :) So I thought you guys would soon find this problem just as I did. Next time I will provide more useful information before I submit an issue.

matklad commented 4 years ago

A reproduction:

cargo run --release -p ra_cli -- --only "try_reduce_with" ~/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.2.0

https://github.com/rayon-rs/rayon/blob/fc69e50f298b2f5fa2ce9be27827a0850f3bc8f2/src/iter/try_reduce_with.rs#L7-L19

matklad commented 4 years ago

https://github.com/rust-analyzer/rust-analyzer/pull/2059 fixes semi-related problem, which should make this issue rarer in practice.

Robbepop commented 4 years ago

@matklad any news about this? the problem for me is still pretty significant although I have the feeling it has slightly improved.

matklad commented 4 years ago

The root cause (chalk allocating in a loop) is not yet fixed iirc. @flodiebold do we have an issue on the chalk repo which tracks this? Or only they Zulip thread?

flodiebold commented 4 years ago

Only the Zulip thread, as far as I know.

pszpetkowski commented 4 years ago

@matklad I've just experienced the issue while looking at Iterator trait definition. It caused memory usage to quickly skyrocket and after a while it has triggered OOMK:

[10717.403818] [  pid  ]   uid  tgid total_vm      rss pgtables_bytes swapents oom_score_adj name
...
[10717.404125] [  13894]  1000 13894  3539510  1760443 26292224  1377237           300 ra_lsp_server
[10717.404127] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice/user-1000.slice/user@1000.service,task=ra_lsp_server,pid=13894,uid=1000
[10717.404169] Out of memory: Killed process 13894 (ra_lsp_server) total-vm:14158040kB, anon-rss:7041772kB, file-rss:0kB, shmem-rss:0kB
matklad commented 4 years ago

zulip thread in question: https://rust-lang.zulipchat.com/#narrow/stream/144729-wg-traits/topic/infinite.20stack.20growth.20in.20chalk

EDIT: upstream issue: https://github.com/rust-lang/chalk/issues/280

bkchr commented 4 years ago

I'm still seeing this very regularly. Do you need something to reproduce this?

estin commented 4 years ago

Same problem for me on commit de2409702ba639f06cf340f5e3f3b7e671021d1b

Check for reproduce https://gist.github.com/estin/393600a78a2891164aaa9db453d88e84

I found it by using nvim + coc.vim + coc-rust-analyzer on my https://github.com/estin/cywad All available system memory used. Only killing ra helps...

Sorry for my poor English.

jonas-schievink commented 4 years ago

The chalk bug is now fixed. @estin's panic still happens, but memory usage looks normal. Closing as fixed.

I've reduced the panic and will open a new bug report.

jonas-schievink commented 4 years ago

Filed https://github.com/rust-analyzer/rust-analyzer/issues/4931