This is sort of like a tracking issue, but specifically for the optimizations I am making (or plan to make) to rustc's macros-by-example implementation. I'm using it to maintain a public list of my ideas on this topic and link together the relevant PRs.
@nnethercote is reviewing these PRs, I'm really grateful for all his help :)
Depth-first traversal for macro parsing (ongoing)
Until now, macro parsing uses a breadth-first traversal strategy for exploring possibly ambiguous parse trees. I believe a depth-first approach would play better with the CPU, e.g. for branch prediction, as well as unlocking bigger optimizations (e.g. it would allow the Rc<Vec<NamedMatch>> in each MatcherPos to be amortized).
Work started 2026-05-22.
Overall results:
- Nice perf wins, even in preparatory PRs.
- Made user-visible details (e.g. ordering within error messages) independent of implementation details.
- Added more internal documentation.
- Conceptually unified two kinds of ambiguity detection (meta-variables and EOF).
- Removed some unreachable paths.
- Moved more diagnostic code to
diagnostics.rs.
Others
Note: these are ideas / proposals, and not all of them might pan out.
This is sort of like a tracking issue, but specifically for the optimizations I am making (or plan to make) to rustc's macros-by-example implementation. I'm using it to maintain a public list of my ideas on this topic and link together the relevant PRs.
@nnethercote is reviewing these PRs, I'm really grateful for all his help :)
Depth-first traversal for macro parsing (ongoing)
Until now, macro parsing uses a breadth-first traversal strategy for exploring possibly ambiguous parse trees. I believe a depth-first approach would play better with the CPU, e.g. for branch prediction, as well as unlocking bigger optimizations (e.g. it would allow the
Rc<Vec<NamedMatch>>in eachMatcherPosto be amortized).Work started 2026-05-22.
diagnostics.rsOverall results:
diagnostics.rs.Others
Note: these are ideas / proposals, and not all of them might pan out.
ParseNtResultintoTokenStreamearlier #159366TokenStreamallocations when transcribing meta-variablesMatchertype to hold and extend&[MatcherLoc]MatcherLoc::DelimitedMatcherLoc::Tokens when buildingMatcherLocs (for now)MatcherLocVecinstead ofHashMapinNamedMatchesVecs inNamedMatchMatcherPos::matchesTtParserin thread-local storageCow<Parser<'_>>with an explicit fast pathmbe::TokenStreamwith an auxiliary table$($x:tt)*to speed up tt-munchersexpand_macro()