Stream: t-compiler/wg-rls-2.0

Topic: perf issues


Brennan Vincent (Apr 28 2020 at 16:33, on Zulip):

I have an example where textDocument/references is taking about a minute with rust-analyzer pegged at 100% CPU , whereas IntelliJ "Find Usages" takes low single-digit seconds on the same piece of code. What is the best way to debug or report this issue?

Laurențiu Nicola (Apr 28 2020 at 16:37, on Zulip):

Does this only happen only on the first request(s), or every time?

Brennan Vincent (Apr 28 2020 at 16:37, on Zulip):

first request.

Brennan Vincent (Apr 28 2020 at 16:38, on Zulip):

(It is also the first request in IntelliJ)

Laurențiu Nicola (Apr 28 2020 at 16:39, on Zulip):

See https://github.com/rust-analyzer/rust-analyzer/issues/1650 for the backstory. There's no persistence support, so the server has to analyze the whole project. https://github.com/rust-analyzer/rust-analyzer/pull/4133 should have helped a little.

Brennan Vincent (Apr 28 2020 at 16:40, on Zulip):

@Laurențiu Nicola It doesn't seem like persistence would account for the difference. In IntelliJ I invalidated the cache before trying, so I don't think it was benefiting from persistence.

Brennan Vincent (Apr 28 2020 at 16:41, on Zulip):

I am using master from git, updated and built today, so I should already have #4133 applied.

Laurențiu Nicola (Apr 28 2020 at 16:42, on Zulip):

Ah, okay, then we're just slower. #4133 just hides the problem under the rug by pre-computing more things when you load a project, but doesn't help if you do the test immediately.

Brennan Vincent (Apr 28 2020 at 16:44, on Zulip):

yes, also, I waited until the initial CPU spike from rust-analyzer ended before trying. So it should have been done building whatever indices it does on startup. BTW, this is about find references, not jump to definition.

Laurențiu Nicola (Apr 28 2020 at 16:44, on Zulip):

For high-level profiling, maybe see https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/dev#profiling. Generally, code profilers that work with C also work with Rust, but it might help to bump up the debug info level in Cargo.toml. I was looking at a profile earlier today, most of it seems to be trait solving.

Laurențiu Nicola (Apr 28 2020 at 16:45, on Zulip):

How large is your project?

Brennan Vincent (Apr 28 2020 at 16:45, on Zulip):

According to perf, the time is spent in chalk_solve::recursive::Solver<I>::solve_goal

Laurențiu Nicola (Apr 28 2020 at 16:47, on Zulip):

Brennan Vincent said:

According to perf, the time is spent in chalk_solve::recursive::Solver<I>::solve_goal

Yup, trait solving

Brennan Vincent (Apr 28 2020 at 16:48, on Zulip):

The repo is https://github.com/MaterializeInc/materialize

~/c/materialize ❯❯❯ find src -name '*.rs' | xargs wc -l | grep total
  92434 total

So, 92kloc including whitespace. I've also added differnetial-dataflow to my workspace which is ~15kloc

Brennan Vincent (Apr 28 2020 at 16:51, on Zulip):

the code is somewhat heavy on traits/generics.

Laurențiu Nicola (Apr 28 2020 at 16:54, on Zulip):

What symbol are you using calling find all references on?

Brennan Vincent (Apr 28 2020 at 16:55, on Zulip):

pub struct Context in src/dataflow/render/context.rs

Laurențiu Nicola (Apr 28 2020 at 16:56, on Zulip):

Oh, yeah, that's slow

Brennan Vincent (Apr 28 2020 at 16:58, on Zulip):

Yeah, to be clear, rust-analyzer is mostly working fine on this codebase.

Laurențiu Nicola (Apr 28 2020 at 17:01, on Zulip):

I'm not sure how actionable this is today. chalk is still mostly unoptimized, and we don't have a way to extract a chalk input from a Rust project. @Florian Diebold might chime in, though.

Brennan Vincent (Apr 28 2020 at 17:02, on Zulip):

Thanks for looking anyway. I was wondering if there is anything simple I could do to help like provide logs, etc., but it sounds like you were able to repro.

Brennan Vincent (Apr 28 2020 at 17:03, on Zulip):

last time I tried rust-analyzer was summer 2019; I gave up and switched to IntelliJ. But this time around it seems much more usable :) So congrats on all the hard work / progress, despite these random minor issues.

Laurențiu Nicola (Apr 28 2020 at 17:03, on Zulip):

I think we already have a couple of recent issues for "chalk is slow", but it wouldn't hurt if youfiled one.

Jack Huey (Apr 28 2020 at 17:04, on Zulip):

Laurențiu Nicola said:

I'm not sure how actionable this is today. chalk is still mostly unoptimized, and we don't have a way to extract a chalk input from a Rust project. Florian Diebold might chime in, though.

That is being worked on :)

Jack Huey (Apr 28 2020 at 17:05, on Zulip):

Specific data about Chalk performance is helpful

Brennan Vincent (Apr 28 2020 at 17:14, on Zulip):

Issue filed: https://github.com/rust-analyzer/rust-analyzer/issues/4194

Laurențiu Nicola (Apr 28 2020 at 17:18, on Zulip):

render::build_dataflow, render::render_join and friends also take a lot of time to analyze

Brennan Vincent (Apr 28 2020 at 17:37, on Zulip):

@Laurențiu Nicola Those are some pretty complicated functions, so it doesn't surprise me. Did you find that out by looking at some profiling data? Or just by clicking around random stuff and trying it out

Laurențiu Nicola (Apr 28 2020 at 17:37, on Zulip):

Ran rust-analyzer analysis-stats and eyeballed it spending 30-60 seconds on those

Last update: Sep 30 2020 at 16:30UTC