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
- Fix accidently quadratic behavior when processing includes closes #3927 — committed to matklad/rust-analyzer by matklad 4 years ago
- Merge #3933 3933: Fix accidently quadratic behavior when processing include! r=matklad a=matklad This fixes the immediate problem behind #3927. It doesn't yet fix the deeper problem with `to_node` b... — committed to rust-lang/rust-analyzer by bors[bot] 4 years ago
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_nodeis 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:
– Cheers,
Edwin Cheng
@matklad is our test suite
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_delimis 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
loadOutputiDirsconfig enabled? The work-around might be to disable it…