rust-analyzer: Performance regression after salsa migration
rust-analyzer version: rust-analyzer version: 0.3.2345-standalone (b0632f749e 2025-03-16)
rustc version: rustc 1.85.0 (4d91de4e4 2025-02-17)
editor or extension: VSCode version 1.98, rust-analyzer extension version 0.3.2345
relevant settings: Mostly N/A. I tried disabling cache priming as mentioned in #19402, and while initial startup was faster, the first request becomes so slow that overall performance seems about the same.
repository link (if public, optional): Private
code snippet to reproduce: Monorepo containing one Rust workspace with ~100 member crates
See profile output with the regression: ra_profile_0_3_2345.txt
For comparison, here is the profile logs after downgrading back to 0.3.2337:
ra_profile_0_3_2337.txt
TL;DR: New version takes 112674ms in parallel_prime_caches where the old version took 25970ms in parallel_prime_caches.
Additionally, I noticed that the new version seems to randomly hang indefinitely at 100% cpu usage after using it for a few minutes (then I need to restart which then needs to re-index). I haven’t included the logs for this, because they are extremely large and contain a lot of files/paths/etc. (new version log file is ~750MB using RA_LOG=info) that I would need to redact before I could share it here.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 28 (17 by maintainers)
https://github.com/rust-lang/rust-analyzer/pull/19474 will fix this, and it should also prevent us from messing up the cwd here again. Sorry for the time loss, and thanks a lot for debugging this!
Ugh, ye that change is actually plain wrong! I mixed up where how this is used. I thought the working directory is looked up for proc-macro definition crate, but its looked up in the calling crate!
Very odd that this has a performance impact for you though, if anything this should cause some macros to just not work.
Oh wow, I think I have isolated the specific lines that changed to here. On a whim, I reverted that specific change back to
And the performance returned to normal. And now it occurs to me that the only other difference in the fast/slow request payloads above was the presence/absence of a
current_dirfield. I didn’t think anything of it at the time, because I assumed that if the directory were important then it would cause an error, not a performance regression.@Veykril, I don’t understand the context of the change, but could it be as simple as changing that back to pass the directory?
Sure, I will try to do that today. In the meantime, yesterday I added deeper tracing, and arrived all the way down to where the rust internal proc-macro expansion logic is being called here and determined that basically all of the performance regression is happening inside that call (despite the inputs being nearly identical). I even logged the
parsed_attributesandparsed_bodyand they are also effectively identical as near as I can tell.I will work on confirming the precise commit where the regression occurs, but I wonder if perhaps this is a side-effect of incrementality somehow? (grain of salt: I have not read through any of the PRs/implementation details and am just reasoning based on the word “incrementality”) Like perhaps the rstest proc-macro is slow to expand the first time it is expanded within an incremental “unit” (not sure if “compilation unit” is the correct term), but since we have a large number of crates, that is a large number of “cold” expansions.
Anyway, I will keep you all posted on my findings regarding the offending commit.