Skip to content

Conversation

@camchenry
Copy link
Member

@camchenry camchenry commented Oct 20, 2025

Getting file extensions shows up as slow in multiple rules. Computing it once and then storing it should be much faster.

Screenshot 2025-10-20 at 12 00 35 AM

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


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 20, 2025

CodSpeed Performance Report

Merging #14794 will not alter performance

Comparing 10-19-perf_linter_cache_file_extension (8a1a226) with main (d39bed0)1

Summary

✅ 4 untouched
⏩ 33 skipped2

Footnotes

  1. No successful run was found on main (46b9d57) during the generation of this report, so d39bed0 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 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 20, 2025 04:01
@camchenry camchenry requested a review from camc314 as a code owner October 20, 2025 04:01
Copilot AI review requested due to automatic review settings October 20, 2025 04:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes linter performance by caching file extensions to avoid repeated computation. Instead of calling file_path().extension() multiple times across different rules, the file extension is now computed once during context initialization and stored for reuse.

  • Adds file_extension() method to ContextHost and LintContext that returns cached extension
  • Updates all Vue, React, Jest, ESLint, and Unicorn rules to use the new cached method
  • Removes redundant imports and simplifies extension checking logic in several files

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/oxc_linter/src/context/host.rs Adds file extension caching field and getter method to ContextHost
crates/oxc_linter/src/context/mod.rs Adds file_extension() method to LintContext that delegates to ContextHost
crates/oxc_linter/src/rules/vue/*.rs Updates Vue rules to use cached file extension method
crates/oxc_linter/src/rules/react/*.rs Updates React rules to use cached file extension method
crates/oxc_linter/src/rules/jest/no_large_snapshots.rs Simplifies snapshot file detection using cached extension
crates/oxc_linter/src/rules/eslint/*.rs Updates ESLint rules to use cached file extension method
crates/oxc_linter/src/rules/unicorn/no_empty_file.rs Optimizes extension comparison using cached method

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Boshen
Copy link
Member

Boshen commented Oct 20, 2025

Interesting to see this is hot 🤯

@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Oct 20, 2025
Copy link
Contributor

camc314 commented Oct 20, 2025

Merge activity

Getting file extensions shows up as slow in multiple rules. Computing it once and then storing it should be much faster.

<img width="713" height="366" alt="Screenshot 2025-10-20 at 12 00 35 AM" src="https://github.com/user-attachments/assets/b074bbf1-8a1f-4910-98d0-40f66eb3b39c" />
@graphite-app graphite-app bot force-pushed the 10-19-perf_linter_cache_file_extension branch from 8a1a226 to 7be9489 Compare October 20, 2025 08:17
@graphite-app graphite-app bot merged commit 7be9489 into main Oct 20, 2025
20 checks passed
@graphite-app graphite-app bot deleted the 10-19-perf_linter_cache_file_extension branch October 20, 2025 08:22
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Oct 20, 2025
@camc314 camc314 self-assigned this Oct 20, 2025
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