Skip to content

perf: skip nonstandard_macro_braces work when the lint is disabled - #3

Closed
xmakro wants to merge 1 commit into
masterfrom
perf/nonstandard-macro-braces-guard
Closed

perf: skip nonstandard_macro_braces work when the lint is disabled#3
xmakro wants to merge 1 commit into
masterfrom
perf/nonstandard-macro-braces-guard

Conversation

@xmakro

@xmakro xmakro commented Jun 1, 2026

Copy link
Copy Markdown
Owner

NONSTANDARD_MACRO_BRACES is a nursery (allow-by-default) lint, but is_offending_macro ran on every item, stmt, expr and ty regardless of whether the lint was enabled. For each node it walked the full macro backtrace (which clones ExpnData and re-enters the hygiene thread-local once per level) and hashed macro names against the brace map. When the lint is disabled none of that can produce a warning, so it is all wasted.

The fix adds two early returns at the top of is_offending_macro:

  1. If the span is not from a macro, return right away. This matches what the original loop already did, but it happens before the lint-level lookup so ordinary non-macro nodes stay as cheap as before.
  2. If the span is from a macro but the lint is allowed at that node, skip the walk.

When the lint is enabled the second guard is never taken, so behaviour is unchanged.

Benchmarked performance, same-binary A/B with perf stat, N=12 medians. Two drivers built against identical libs, differing only in this change:

crate instructions branches task-clock
wasmi -8.34% -8.05% -4.69%
serde -0.19% -0.24% -0.86%
tokio -0.19% -0.19% -0.25%
ripgrep -0.06% -0.07% +0.31%
syn -0.02% -0.04% -0.24%
regex +0.01% +0.01% +0.17%

The improvement is on macro-heavy code, the rest are within noise

…sabled

`NONSTANDARD_MACRO_BRACES` is a nursery (allow-by-default) lint, but
`is_offending_macro` ran on every item/stmt/expr/ty unconditionally:
walking the full macro backtrace (`outer_expn_data` clone + hygiene
thread-local re-entry) and hashing macro names against the brace map,
even though nothing could be emitted when the lint is disabled.

Bail out early on two cheap checks. First, if the span isn't from a
macro there is nothing to do (same as the original loop, but before any
lint-level lookup so the common non-macro node stays free). Then, once we
know the span came from a macro, skip everything when the lint is allowed
at this node. Behaviour is unchanged when the lint is enabled.

Same-binary A/B (instructions, N=12 medians) on macro-heavy code shows
wasmi -8.3%; macro-light crates (tokio/syn/regex/ripgrep/serde) stay
within noise. Diagnostics are byte-identical and the UI test is green.
@xmakro
xmakro force-pushed the perf/nonstandard-macro-braces-guard branch from 695b6c1 to f4e0c41 Compare June 1, 2026 04:00
@xmakro xmakro closed this Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant