-
Notifications
You must be signed in to change notification settings - Fork 2k
Optimize MBE (macro by example) performance #7857
Copy link
Copy link
Open
Labels
A-macromacro expansionmacro expansionA-perfperformance issuesperformance issuesE-has-instructionsIssue has some instructions and pointers to code to get startedIssue has some instructions and pointers to code to get startedS-actionableSomeone could pick this issue up and work on it right nowSomeone could pick this issue up and work on it right nowfunA technically challenging issue with high impactA technically challenging issue with high impactgood first issue
Metadata
Metadata
Assignees
Labels
A-macromacro expansionmacro expansionA-perfperformance issuesperformance issuesE-has-instructionsIssue has some instructions and pointers to code to get startedIssue has some instructions and pointers to code to get startedS-actionableSomeone could pick this issue up and work on it right nowSomeone could pick this issue up and work on it right nowfunA technically challenging issue with high impactA technically challenging issue with high impactgood first issue
Type
Fields
Give feedbackNo fields configured for issues without a type.
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 --nocaptureOutput should be something like:
Source
The corresponding source code of mbe expander is at :
https://github.com/rust-analyzer/rust-analyzer/blob/3b507aa90fca9618ddbe0667e245ef4766aa96b5/crates/mbe/src/expander/matcher.rs#L148-L151
And we have a bunch of compliance tests related to mbe, to run these test :
$ cargo test --package mbe -- --nocaptureTips
By default, RA turn off the debug information in
Cargo.toml:https://github.com/rust-analyzer/rust-analyzer/blob/3b507aa90fca9618ddbe0667e245ef4766aa96b5/Cargo.toml#L18-L20
You may need to set it to
debug = 2And here is how I run
perfin 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]