| name | performance-lint-rules |
| description | Performance review guidance for Oxc linter rule implementations. Use only when reviewing Rust rule code under crates/oxc_linter/src/rules/ or when explicitly auditing those rules for performance improvements. |
Performance Guidelines
Prefer top-level node kind checks
Put node kind checks at the rule entry point. If a rule only handles a few syntactic forms, start run with an AstKind match and return for all other nodes, even when a helper filters again internally. This lets lintgen derive narrower NODE_TYPES and avoids dispatching the rule on unrelated AST nodes.
After changing the relevant node kinds for a rule, regenerate the rule runner with cargo lintgen and consider adding or updating assert_rule_runs_on_node_types coverage in crates/oxc_linter/src/rule.rs.
Implement only the needed entry point. If a rule is a whole-file pass over semantic indexes, use run_once by itself. Implementing both run and run_once prevents useful node-type narrowing.
Do cheaper checks first
Order checks from cheapest and most selective to most expensive. Return quickly for common non-matches before doing semantic lookups, allocations, or deeper traversal.
- Matching a small fixed string set with
matches! before semantic checks.
- Rejecting lowercase identifiers before global-object checks when only constructors can match.
- Checking whether a JSX attribute starts with
aria- before lowercasing it.
- Checking for required syntax such as a
key prop before looking up callback parameter symbols.
- Checking
source_range(span).contains("this") before running a visitor that only finds this.