rust-lang / rust-lang/rust-analyzer
Performance degradation when using big tt-muncher `macro_rules`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
I recently noticed a big performance degradation regarding rust-analyzer in one of my projects: https://github.com/paritytech/wasmi
The problem is that rust-analyzer consumes much more memory than it has used to and also very often get stuck and shows incorrect warnings and won't finish analysis of the crate and therefore is pretty much unusable for the project. I noticed a very similar behavior of rust-analyzer in the https://github.com/bytecodealliance/wasm-tools repository.
After some backtracking I found that the performance regressions started after merging these PRs:
What do the PRs do?
They refactor use of wasmparser's for_each_operator macro which is supposed to be used as tt-muncher macro in order to perform operations on the over 500 different Wasm operators.
My best guess at what portion of wasmi causes the choking for rust-analyzer is probably these code segments:
- https://github.com/paritytech/wasmi/blob/3e6d0d63846ff7c3000c0934e00ad0d34ea6a10f/crates/wasmi/src/engine/func_builder/mod.rs#L177
- https://github.com/paritytech/wasmi/blob/3e6d0d63846ff7c3000c0934e00ad0d34ea6a10f/crates/wasmi/src/engine/func_builder/translator.rs#L642
Note that in particular in https://github.com/paritytech/wasmi/pull/645 we had to increase macro recursion limit in lib.rs:
#![recursion_limit = "750"]
Sometimes I succeed in getting rust-analyzer unstuck by performing a cargo clean on my workspace. However, this is notably not a very neat solution for obvious reasons.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the regression with the wasmi and wasm-tools repositories, then inspect the referenced func_builder/mod.rs and func_builder/translator.rs locations and the macro recursion_limit change in lib.rs. Compare behavior before and after the referenced wasmi PRs and determine what causes rust-analyzer's memory growth, hangs, and incomplete analysis; done means analysis is usable again without requiring cargo clean.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100