Skip to content

Conversation

@camchenry
Copy link
Member

@camchenry camchenry commented Oct 15, 2025

Adds a new kind of code analysis to the linter codegen. This new detector looks for diverging statements in lint rules, like:

let something = match node.kind() {
  AstKind::CallExpression(_) => { ... }
  _ => return,
}

The important part is that the expression must diverge (i.e., it must have something like a return in its wildcard block). That way, we know only the matched node types in the match arms are used in the rule.

@github-actions github-actions bot added A-linter Area - Linter C-performance Category - Solution not expected to change functional behavior, only performance labels Oct 15, 2025
Copy link
Member Author

camchenry commented Oct 15, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 15, 2025

CodSpeed Performance Report

Merging #14631 will improve performances by 5.65%

Comparing 10-15-perf_linter_detect_diverging_match_blocks_for_node_type_skipping (12a9934) with main (82196e7)

Summary

⚡ 4 improvements
⏩ 33 skipped1

Benchmarks breakdown

Mode Benchmark BASE HEAD Change
Instrumentation linter[RadixUIAdoptionSection.jsx] 1.1 ms 1 ms +7.85%
Instrumentation linter[binder.ts] 63.4 ms 59.4 ms +6.8%
Instrumentation linter[cal.com.tsx] 583.4 ms 552.2 ms +5.65%
Instrumentation linter[react.development.js] 23.8 ms 22.4 ms +6.41%

Footnotes

  1. 33 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@camchenry camchenry marked this pull request as ready for review October 15, 2025 15:36
@camchenry camchenry requested a review from camc314 as a code owner October 15, 2025 15:36
@camchenry camchenry force-pushed the 10-15-perf_linter_detect_diverging_match_blocks_for_node_type_skipping branch from 5bd18a8 to 3c0d09b Compare October 15, 2025 15:36
@camc314 camc314 self-assigned this Oct 15, 2025
@graphite-app graphite-app bot changed the base branch from 10-15-perf_linter_update_react_prefer-es6-class_to_use_top-level_match to graphite-base/14631 October 15, 2025 20:51
Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! this is great to see

@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 15, 2025

Merge activity

@graphite-app graphite-app bot changed the base branch from graphite-base/14631 to main October 15, 2025 20:55
…14631)

Adds a new kind of code analysis to the linter codegen. This new detector looks for diverging statements in lint rules, like:

```rust
let something = match node.kind() {
  AstKind::CallExpression(_) => { ... }
  _ => return,
}
```

The important part is that the expression _must_ diverge (i.e., it must have something like a `return` in its wildcard block). That way, we know only the matched node types in the match arms are used in the rule.
@graphite-app graphite-app bot force-pushed the 10-15-perf_linter_detect_diverging_match_blocks_for_node_type_skipping branch from 3c0d09b to 12a9934 Compare October 15, 2025 20:56
@graphite-app graphite-app bot merged commit 12a9934 into main Oct 15, 2025
21 checks passed
@graphite-app graphite-app bot deleted the 10-15-perf_linter_detect_diverging_match_blocks_for_node_type_skipping branch October 15, 2025 21:02
}

// Look at the first statement in the function body.
let stmt = block.stmts.first()?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small note here:

IMO it'd likely be preferable to use block.stmts.first().unwrap().

.unwrap() will often cause the compiler to backtrack and try to prove that the unwrap can't fail. In this case I'd assume it can prove this fairly easily as the block.stmts.len() <= 1 check is right above. So it'll remove the branch. Whereas with ? it probably won't backtrack and won't figure this out.

Someone taught me this surprising fact last year - sometimes a well-placed assert! can result in less code, rather than more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants