rust-lang / rust-lang/rust-analyzer

Performance degradation when using big tt-muncher `macro_rules`

Open
#14,101 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
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:

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.