Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(linter): use aho-corasick instead of regex for string matching in jsx-a11y/img-redundant-alt #5892

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

camchenry
Copy link
Collaborator

hypothesis: profiling shows that Regex creation takes a decent amount of time. the regex crate uses aho-corasick internally for string matching, which is all we need in some cases. in theory, we could save time by using the lib directly and not needing the full regex syntax.

Copy link

graphite-app bot commented Sep 19, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

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

@github-actions github-actions bot added the A-linter Area - Linter label Sep 19, 2024
@camchenry camchenry added the C-performance Category - Solution not expected to change functional behavior, only performance label Sep 19, 2024
Copy link

codspeed-hq bot commented Sep 19, 2024

CodSpeed Performance Report

Merging #5892 will not alter performance

Comparing perf/linter-aho-corasick (608d637) with main (66b4688)

Summary

✅ 29 untouched benchmarks

@camchenry
Copy link
Collaborator Author

Going to implement one more instance, but seems worth it so far: +1% on checker.ts and cal.com benchmarks, and running locally looks like it is a 0.5-3.5% improvement on every benchmark:

Benchmarking linter/checker.ts: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 44.9s, or reduce sample count to 10.
linter/checker.ts       time:   [454.87 ms 457.63 ms 460.90 ms]
                        change: [−4.3676% −2.7467% −1.4866%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) high mild
  3 (3.00%) high severe
Benchmarking linter/cal.com.tsx: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 24.0s, or reduce sample count to 20.
linter/cal.com.tsx      time:   [231.69 ms 232.15 ms 232.67 ms]
                        change: [−4.6489% −3.6682% −2.8229%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 16 outliers among 100 measurements (16.00%)
  4 (4.00%) high mild
  12 (12.00%) high severe
linter/RadixUIAdoptionSection.jsx
                        time:   [520.46 µs 522.86 µs 526.14 µs]
                        change: [−1.2572% −0.7420% −0.1586%] (p = 0.01 < 0.05)
                        Change within noise threshold.
Found 5 outliers among 100 measurements (5.00%)
  3 (3.00%) high mild
  2 (2.00%) high severe
Benchmarking linter/pdf.mjs: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 14.8s, or reduce sample count to 30.
linter/pdf.mjs          time:   [146.08 ms 146.50 ms 146.96 ms]
                        change: [−3.5880% −2.9178% −2.3221%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
  5 (5.00%) high mild
Benchmarking linter/antd.js: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 87.9s, or reduce sample count to 10.
linter/antd.js          time:   [895.88 ms 900.83 ms 906.04 ms]
                        change: [−0.3027% +0.5075% +1.3183%] (p = 0.22 > 0.05)
                        No change in performance detected.
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high mild

@Boshen
Copy link
Member

Boshen commented Sep 19, 2024

✅ I tried to rewrite all regexes into string matchers when I started porting rules, but I never told other contributors to rewrite them because it takes too much effort.

I even have a policy of avoiding regexes https://oxc.rs/docs/contribute/rules.html#development-policy

@camchenry camchenry changed the title perf(linter): use aho-corasick instead of regex for string matching perf(linter): use aho-corasick instead of regex for string matching in jsx-a11y/img-redundant-alt Sep 19, 2024
@camchenry camchenry marked this pull request as ready for review September 19, 2024 21:45
Copy link
Collaborator Author

Cargo.toml Outdated Show resolved Hide resolved
@DonIsaac DonIsaac added the 0-merge Merge with Graphite Merge Queue label Sep 19, 2024
Copy link

graphite-app bot commented Sep 19, 2024

Merge activity

  • Sep 19, 6:39 PM EDT: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Sep 19, 6:39 PM EDT: DonIsaac added this pull request to the Graphite merge queue.
  • Sep 19, 6:44 PM EDT: DonIsaac merged this pull request with the Graphite merge queue.

…ng in `jsx-a11y/img-redundant-alt` (#5892)

hypothesis: profiling shows that Regex creation takes a decent amount of time. the `regex` crate uses `aho-corasick` internally for string matching, which is all we need in some cases. in theory, we could save time by using the lib directly and not needing the full regex syntax.
@graphite-app graphite-app bot merged commit 608d637 into main Sep 19, 2024
26 checks passed
@graphite-app graphite-app bot deleted the perf/linter-aho-corasick branch September 19, 2024 22:44
@oxc-bot oxc-bot mentioned this pull request Sep 23, 2024
Boshen added a commit that referenced this pull request Sep 23, 2024
## [0.9.7] - 2024-09-23

### Features

- d24985e linter: Add `oxc-security/api-keys` (#5906) (DonIsaac)
- f9b44c5 linter: Add unicode sets support to `no-useless-escape` rule
(#5974) (camchenry)
- 0f19848 linter: Implement `no-unexpected-multiline` rule (#5911)
(camchenry)
- 16fe383 linter: Implement `no-extend-native` rule (#5867) (Cam
McHenry)

### Bug Fixes

- eed9ac7 linter: Include actual span size in `no-regex-spaces`
diagnostic (#5957) (camchenry)
- 40c89c2 linter: Move `promise/avoid-new` to style category (#5961)
(DonIsaac)

### Performance

- 608d637 linter: Use `aho-corasick` instead of `regex` for string
matching in `jsx-a11y/img-redundant-alt` (#5892) (camchenry)
- 3148d4b linter: Check file path after checking node kind for
`nextjs/no-head-element` (#5868) (Cam McHenry)

### Refactor

- 0a5a4a9 linter: Use parsed patterns for `unicorn/no-hex-escape`
(#5985) (camchenry)
- 2cf2edd linter: Use parsed patterns in `no-empty-character-class` rule
(#5980) (camchenry)
- a9a8e2a linter: Use regex parser in `eslint/no-regex-spaces` (#5952)
(camchenry)
- 05f592b linter: Use parsed patterns in
`unicorn/prefer-string-starts-ends-with` (#5949) (camchenry)
- 3273b64 linter: Use parsed patterns for
`unicorn/prefer-string-replace-all` rule (#5943) (camchenry)
- ba7b01f linter: Add `LinterBuilder` (#5714) (DonIsaac)
- db4f16a semantic: Call `with_trivias` before `build_with_jsdoc`
(#5875) (Boshen)
- 3d13c6d semantic: Impl `IntoIterator` for `&AstNodes` (#5873)
(DonIsaac)

### Testing

- b681c9a linter: Import test cases for `no-empty-character-class`
(#5981) (camchenry)
- 767602b linter: Add regression test for #5227 (#5975) (camchenry)

---------

Co-authored-by: Boshen <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0-merge Merge with Graphite Merge Queue 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.

3 participants