rust-analyzer: rust-analyzer's initial-loading is slow and blocks typing

Repro

Observation

The initial loading (or whatever it is, because there is no indicator that rust-analyzer is parsing or whatever) takes over 4 minutes on my system. And while it’s loading I am “unable” to type characters like new-line. Hovering over functions (the main function in particular) produces a “Loading…” tool-tip.

I am not quite sure, however some weeks ago I didn’t experienced such slow initial-loading. I know that there are lots of peer dependencies however I would expect rust-analyzer not blocking the editor and at least showing that it’s doing something (with some kind of visual indicator).

vscode rust-analyzer output:

[ERROR rust_analyzer::main_loop] overly long loop turn: 77.044804439s

System:

  • CPU: i7-6700K (4/8 physical/logical-cores)
  • RAM: 32GB DDR4
  • Linux: 5.6.3-arch1-1
  • rustc: 1.44.0-nightly (94d346360 2020-04-09)
  • rust-analyzer: current master (38e0d0f)
  • vscode: 1.45.0-insider (c12bd56a8886f31e353a45f5846f0a35a52f908e)

EDIT:

  • The dependencies have been reduced to a single one tera = "1.1.0" (And including its peer-deps).

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 6
  • Comments: 17 (16 by maintainers)

Commits related to this issue

Most upvoted comments

I have good and bad news:

bad news is that literally everything is quadratic. Specifically, every time we get a source for an element, it can be O(N^2), as SyntaxNodePtr::to_node is quadratic.

good news is that if I make it faster, I’ll speed up a bunch of stuff 😄

I had too much whiskey 🥃 to review now, tomorrow will be much better 😂

On Sat, 11 Apr 2020 at 01:17, Aleksey Kladov notifications@github.com wrote:

I am already first 90% into the fix, hope to give you something for review tomorrow 😄

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rust-analyzer/rust-analyzer/issues/3927#issuecomment-612128966, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUA7Z45BJ27PV35LIOVW5DRL5IDZANCNFSM4MFQJKQA .

– Cheers,

Edwin Cheng

@matklad is our test suite

first 90%

This is so true. The fix was easy, but, after writing the test, I’ve found that something in type-infernece is quadratic as well. And, while pofiing the inference, I’ve noticed that our profiler has a bug and under reports the time.

Found it, TokenMap::update_close_delim is accidentally quadratic. A classic!

Ok, so we spend a lot of time processing this file: https://gist.github.com/matklad/644fc209e71b11a01567710e86dde99a .

I’ve reproduced this with rust-analyzer analysis-stats --load-output-dirs . Hasn’t finished yet 😄

@cynecx do you have loadOutputiDirs config enabled? The work-around might be to disable it…