Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upOptimize the DFA inner loop. #202
Conversation
This comment has been minimized.
This comment has been minimized.
|
Comparison with current master:
|
This comment has been minimized.
This comment has been minimized.
|
Nice! Everything about I wonder if it'd be worth investigating some fuzzing techniques like afl to test this out a bit? I'm pretty happy with the level of comments and thought here though, so I'd be fine merging at any time :) |
This comment has been minimized.
This comment has been minimized.
|
Fuzzing is definitely a good idea. There is some fuzzy in |
BurntSushi
merged commit 01f23d2
into
master
Apr 13, 2016
BurntSushi
referenced this pull request
Apr 13, 2016
Closed
decrease memory usage of DFA with variable width delta encoding of instruction pointers #199
BurntSushi
deleted the
opt-dfa
branch
Apr 13, 2016
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.
BurntSushi commentedApr 13, 2016
This employs a number of tricks to make the inner loop faster:
unsafe. This is the first use ofunsafein regex. It is justified below with benchmarks, and commentsin the source make an argument for correctness.
This reduces the amount of branching needed.
non-dead, non-match and non-start states. (i.e., The majority of cases.)
In particular, this lets us avoid having to check specifically whether
each state is a match state or not. It is unrolled 4 times.
that we should scan for. Otherwise, start states are no different than
any other state.
Stateand into one giant transition table,which should hopefully improve locality and make better use of the
cache.
The use of
unsafeis unfortunate, but it significantly reduces thenumber of instructions executed in a search. When the DFA spends a lot
of time in the inner loop, eliding the bounds checks leads to better
performance. In most cases, the boost is worth about 5%, but in some
extreme cases (e.g., a match is the entirety of a large haystack), the
boost can be worth nearly 50%.
Here is a comparison between code without
unsafeand withunsafe: