Use AhoCorasick to speed up quote match#9773
Merged
charliermarsh merged 1 commit intomainfrom Feb 2, 2024
Merged
Conversation
charliermarsh
commented
Feb 2, 2024
| Some("\"") | ||
| } else { | ||
| None | ||
| } |
Member
Author
There was a problem hiding this comment.
This is also a bit faster than the iterator approach though both are quite fast (1ns vs. 800ps).
Member
Author
|
I bet we could speed this up even more but this feels like good bang for buck: https://lemire.me/blog/2023/07/14/recognizing-string-prefixes-with-simd-instructions/ |
Contributor
|
MichaReiser
approved these changes
Feb 2, 2024
BurntSushi
approved these changes
Feb 2, 2024
| .chain(SINGLE_QUOTE_STR_PREFIXES) | ||
| .chain(SINGLE_QUOTE_BYTE_PREFIXES), | ||
| ) | ||
| .unwrap() |
Member
There was a problem hiding this comment.
Perfect. I'm glad you found StartKind::Anchored.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When I was looking at the v0.2.0 release, this method showed up in a CodSpeed regression (we were calling it more), so I decided to quickly look at speeding it up. @BurntSushi suggested using Aho-Corasick, and it looks like it's about 7 or 8x faster:
Test Plan
cargo test