automata/nfa/thompson: tweak allocation handling for UTF-8 compiler - #1386
Open
BurntSushi wants to merge 1 commit into
Open
automata/nfa/thompson: tweak allocation handling for UTF-8 compiler#1386BurntSushi wants to merge 1 commit into
BurntSushi wants to merge 1 commit into
Conversation
This commit makes the UTF-8 compiler allocation pattern a bit more lazy. Instead of allocating 10,000 entries up-front, we now allocate via a smaller chunking pattern. That is, we only allocate N chunks up front, and each chunk is itself only allocated only when we actually try to put something inside of it. This also adds a few unit tests covering existing and new behavior. This addresses #1316 by making compilation of that regex substantially faster. Previously, this program ``` fn main() { for _ in 0..100000 { let re = regex::bytes::RegexBuilder::new(r"^[^/]+/foo/[^/]+$") .unicode(true) .build() .unwrap(); assert!(re.is_match(b"bar/foo/baz")); } } ``` took about 1.86s to run. But with this change, it only takes 1.14s to run. This still isn't quite as good as the non-Unicode case (which takes 0.64s), but we're closer with this change. Fixes #1316
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.
This commit makes the UTF-8 compiler allocation pattern a bit more lazy.
Instead of allocating 10,000 entries up-front, we now allocate via a
smaller chunking pattern. That is, we only allocate N chunks up front,
and each chunk is itself only allocated only when we actually try to put
something inside of it.
This also adds a few unit tests covering existing and new behavior.
This addresses #1316 by making compilation of that regex substantially
faster. Previously, this program
took about 1.86s to run. But with this change, it only takes 1.14s to
run. This still isn't quite as good as the non-Unicode case (which takes
0.64s), but we're closer with this change.
Fixes #1316