Skip to content

perf(linter/no-inner-declarations): remove unnecessary code and reduce branches#11633

Merged
graphite-app[bot] merged 1 commit intomainfrom
06-12-perf_linter_no-inner-declarations_remove_unnecessary_code_and_reduce_branches
Jun 12, 2025
Merged

perf(linter/no-inner-declarations): remove unnecessary code and reduce branches#11633
graphite-app[bot] merged 1 commit intomainfrom
06-12-perf_linter_no-inner-declarations_remove_unnecessary_code_and_reduce_branches

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Jun 12, 2025

  1. Remove unnecessary check that grandparent of node is a Function or ArrowFunctionExpression when its parent is a FunctionBody. FunctionBody is always the child of Function or ArrowFunctionExpression, so this check is redundant.

  2. If node is a VariableStatement or Function, it always has a parent node. So unwrap the parent instead of branching if let Some(parent_node) = parent. It's always Some.

The 2nd also allows skipping 1 turn of the loop further down because:

  • If direct parent is a StaticBlock, we already exited.
  • It's impossible for a variable or function declaration's parent to be a Function - there'd have to be a FunctionBody in between.

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

overlookmotel commented Jun 12, 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
Copy Markdown

codspeed-hq bot commented Jun 12, 2025

CodSpeed Instrumentation Performance Report

Merging #11633 will create unknown performance changes

Comparing 06-12-perf_linter_no-inner-declarations_remove_unnecessary_code_and_reduce_branches (2cd786b) with main (8776301)

Summary

🆕 38 new benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
🆕 codegen[RadixUIAdoptionSection.jsx] N/A 132.5 µs N/A
🆕 codegen[binder.ts] N/A 4.8 ms N/A
🆕 codegen[cal.com.tsx] N/A 38.8 ms N/A
🆕 codegen[react.development.js] N/A 2.2 ms N/A
🆕 formatter[RadixUIAdoptionSection.jsx] N/A 328.9 µs N/A
🆕 formatter[binder.ts] N/A 20.7 ms N/A
🆕 formatter[cal.com.tsx] N/A 161 ms N/A
🆕 formatter[react.development.js] N/A 10.1 ms N/A
🆕 lexer[RadixUIAdoptionSection.jsx] N/A 21 µs N/A
🆕 lexer[binder.ts] N/A 929.8 µs N/A
🆕 lexer[cal.com.tsx] N/A 5.8 ms N/A
🆕 lexer[react.development.js] N/A 384 µs N/A
🆕 linter[RadixUIAdoptionSection.jsx] N/A 2.6 ms N/A
🆕 linter[binder.ts] N/A 149.5 ms N/A
🆕 linter[cal.com.tsx] N/A 1.2 s N/A
🆕 linter[react.development.js] N/A 54.8 ms N/A
🆕 mangler[RadixUIAdoptionSection.jsx] N/A 14.3 µs N/A
🆕 mangler[binder.ts] N/A 808.5 µs N/A
🆕 mangler[cal.com.tsx] N/A 3.5 ms N/A
🆕 mangler[react.development.js] N/A 284.4 µs N/A
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

@overlookmotel overlookmotel marked this pull request as ready for review June 12, 2025 11:27
@overlookmotel overlookmotel requested a review from camc314 as a code owner June 12, 2025 11:27
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Jun 12, 2025
Copy link
Copy Markdown
Contributor

camc314 commented Jun 12, 2025

Merge activity

…e branches (#11633)

1. Remove unnecessary check that grandparent of node is a `Function` or `ArrowFunctionExpression` when its parent is a `FunctionBody`. `FunctionBody` is always the child of `Function` or `ArrowFunctionExpression`, so this check is redundant.

2. If node is a `VariableStatement` or `Function`, it always has a parent node. So `unwrap` the parent instead of branching `if let Some(parent_node) = parent`. It's always `Some`.

The 2nd also allows skipping 1 turn of the loop further down because:

* If direct parent is a `StaticBlock`, we already exited.
* It's impossible for a variable or function declaration's parent to be a `Function` - there'd have to be a `FunctionBody` in between.
@graphite-app graphite-app bot force-pushed the 06-12-fix_linter_no-inner-declarations_flag_var_statement_as_body_of_for_loop branch from 596e02e to 8776301 Compare June 12, 2025 11:30
@graphite-app graphite-app bot force-pushed the 06-12-perf_linter_no-inner-declarations_remove_unnecessary_code_and_reduce_branches branch from ab485ed to 2cd786b Compare June 12, 2025 11:31
Base automatically changed from 06-12-fix_linter_no-inner-declarations_flag_var_statement_as_body_of_for_loop to main June 12, 2025 11:33
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jun 12, 2025
@graphite-app graphite-app bot merged commit 2cd786b into main Jun 12, 2025
24 checks passed
@graphite-app graphite-app bot deleted the 06-12-perf_linter_no-inner-declarations_remove_unnecessary_code_and_reduce_branches branch June 12, 2025 11:34
Boshen added a commit that referenced this pull request Jun 19, 2025
## [1.2.0] - 2025-06-19

### 🚀 Features

- 8c341a2 sema/check: Ts setters cannot have initializers (#11695) (Don
Isaac)
- 38dc614 oxc_linter: Reuse allocators (#11736) (camc314)
- bf8263d playground: Allow specifying a JSON string as the linter
config (#11710) (Nicholas Rayburn)
- 0b4261b vscode: Add `oxc.requireConfig` configuration (#11700) (Sysix)
- 52ecc87 linter: Implement import/extensions (#11548) (Tyler Earls)
- 094b81c language_server: Add `unusedDisableDirectives` option (#11645)
(Sysix)

### 🐛 Bug Fixes

- 3d88eeb linter/no-console: False negative when `console.*` methods are
used as args to functions (#11790) (camc314)
- c80e405 linter/no-new-wrappers: Fix panic in fixer with multi byte
chars (#11773) (camc314)
- e58a0b0 linter: Panic in unicorn/consistent-function-scoping (#11772)
(camc314)
- 80c87d4 linter: Typo in typescript/consistent-index-object-style
(#11744) (camc314)
- ff775e9 linter/consistent-function-scoping: Descriptive diagnostic
labels (#11682) (Don Isaac)
- 989634a linter/no-inner-declaration: False negative with for loops
(#11692) (camc314)
- b272b91 linter/no-undef: False negative with unresolved ref after type
ref (#11721) (camc314)
- 6252275 linter: Panic in import/extensions with empty file names
(#11720) (camc314)
- f34e432 linter: Use fixer::noop in dangerous cases for eslint/no-var
(#11693) (camc314)
- 6c2b41c linter/consistent-function-scoping: Allow functions in TS
modules/namespaces (#11681) (Don Isaac)
- 2ca1c70 linter/exhaustive-deps: False positive with TS Non null
assertion operator (#11690) (camc314)
- ee15f7d linter: False negative in typescript/prefer-function-type
(#11674) (camc314)
- abd0441 linter: Add missing menuitemradio and menutitemcheckbox roles
(#11651) (Daniel Flynn)
- 8776301 linter/no-inner-declarations: Flag `var` statement as body of
`for` loop (#11632) (overlookmotel)

### 🚜 Refactor

- 5ca3d04 ast: Add `TSArrayType` as `AstKind` (#11745) (camchenry)
- abdbaa9 language_server: Use rule name directly from OxcCode instead
of parsing out of the stringified version of OxcCode (#11714) (Nicholas
Rayburn)
- 219adcc ast: Don't generate AstKind for ArrayExpressionElement
(#11684) (Ulrich Stark)
- c1be6b8 linter: Shorten Span construction (#11686) (Ulrich Stark)
- 4ca659c linter: Cleanup typescript/prefer-function-type (#11672) (Brad
Dunbar)
- 8e30c5f ast: Don't generate AstKind for ForStatementInit (#11617)
(Ulrich Stark)

### 📚 Documentation

- ea6ce9d linter: Fix typo in import/no-namespace (#11741) (camc314)
- 8b6076e linter: Document options for the `typescript/array-type` rule
(#11665) (yefan)

### ⚡ Performance

- f539f64 allocator: Remove `Arc` from `AllocatorPool` (#11760)
(overlookmotel)
- cfdc518 linter/no-inner-declarations: Move work to cold path (#11746)
(overlookmotel)
- 7c0fff7 linter: Skip running `consistent-function-scoping` on `.d.ts`
files (#11739) (camc314)
- b34c6f6 parser,semantic: Improve handling of diagnostics (#11641)
(Boshen)
- 2cd786b linter/no-inner-declarations: Remove unnecessary code and
reduce branches (#11633) (overlookmotel)

### 🧪 Testing

- 44a9df8 linter: Update testsuite for `no-undef` (#11706) (Sysix)

Co-authored-by: Boshen <[email protected]>
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.

2 participants