rust-lang / rust-lang/rust-analyzer
Optimize MBE (macro by example) performance
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Recently (#7513) we implemented a new NFA based expander for MBE which is quite slow compared to the old one (based on recursive descent). It would be nice if someone could optimize it to run as fast as possible.
Benchmark
We already have a benchmark for it, to run the benchmark :
$ RUN_SLOW_TESTS=1 cargo test --release --package mbe -- benchmark::benchmark_expand_macro_rules --nocapture
Output should be something like:
running 1 test
mbe expand macro rules: 2.21s, 8464minstr
test benchmark::benchmark_expand_macro_rules ... ok
Source
The corresponding source code of mbe expander is at :
And we have a bunch of compliance tests related to mbe, to run these test :
$ cargo test --package mbe -- --nocapture
Tips
By default, RA turn off the debug information in Cargo.toml :
You may need to set it to debug = 2
And here is how I run perf in linux:
$ RUN_SLOW_TESTS=1 perf record --call-graph dwarf cargo test --release --package mbe -- benchmark::benchmark_expand_macro_rules --nocapture
$ perf report --call-graph
[EDIT: added --release flag]
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
Start in crates/mbe/src/expander/matcher.rs around the referenced expander code, then run the release benchmark command to establish the baseline. Use profiling as suggested and run the full crates/mbe test suite after changes; done means the benchmark improves without breaking the compliance tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100