Skip to content

Comments

perf(linter): Use aho-corasick instead of regex for default comment patterns in no-fallthrough#5901

Closed
camchenry wants to merge 1 commit intoperf/linter-aho-corasickfrom
09-19-use_aho-corasick_instead_of_regex_for_default_comment_patterns_in_no-fallthrough_
Closed

perf(linter): Use aho-corasick instead of regex for default comment patterns in no-fallthrough#5901
camchenry wants to merge 1 commit intoperf/linter-aho-corasickfrom
09-19-use_aho-corasick_instead_of_regex_for_default_comment_patterns_in_no-fallthrough_

Conversation

@camchenry
Copy link
Member

@camchenry camchenry commented Sep 19, 2024

theory: using Regex is slow in most cases, since we have a fixed number of patterns that we need to search for. but we do still need to support it since the user can pass a custom regex pattern. however, we can at least try to use a simpler aho-corasick matcher for the default strings, which should likely be the majority of cases.

@graphite-app
Copy link
Contributor

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.

Copy link
Member Author

camchenry commented Sep 19, 2024

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

Join @camchenry and the rest of your teammates on Graphite Graphite

@camchenry camchenry changed the title Use aho-corasick instead of regex for default comment patterns in no-fallthrough perf(linter): Use aho-corasick instead of regex for default comment patterns in no-fallthrough Sep 19, 2024
@github-actions github-actions bot added the A-linter Area - Linter label Sep 19, 2024
default_comment_pattern: AhoCorasick::builder()
.ascii_case_insensitive(true)
.build(DEFAULT_FALLTHROUGH_COMMENT_PATTERNS)
.expect("Could not build AhoCorasick for default comment patterns"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we provide the name of the rule so users know where and how to fix their configs?

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 19, 2024

CodSpeed Performance Report

Merging #5901 will not alter performance

Comparing 09-19-use_aho-corasick_instead_of_regex_for_default_comment_patterns_in_no-fallthrough_ (f981bde) with perf/linter-aho-corasick (d7ceb48)

Summary

✅ 29 untouched benchmarks

@camchenry
Copy link
Member Author

I tested this locally and it seems like this might not actually be much of a perf win. Seems like it is 2-3% slower on the large benchmarks like checker.ts and cal.com, but faster in small files (~6-7%), but not at a statistically significant level.

@camchenry camchenry closed this Sep 19, 2024
@DonIsaac
Copy link
Contributor

This PR could still be useful if it lets us remove our dependency on regex

@camchenry
Copy link
Member Author

@DonIsaac I think we still have to depend on regex still unfortunately, because the custom comment pattern config is allowed to be any pattern.

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

Labels

A-linter Area - Linter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants