Resolve all groups when performing match#178
Open
suhothayan wants to merge 3 commits intogoogle:masterfrom
Open
Resolve all groups when performing match#178suhothayan wants to merge 3 commits intogoogle:masterfrom
suhothayan wants to merge 3 commits intogoogle:masterfrom
Conversation
RE2J does not resolve groups when `Matcher.find()` is called, but rater it only resolves groups when `Matcher.group(*)` is called. This results in input being matched twice reducing performance. This fix enables RE2J to resolve the groups when `Matcher.find()` is called, so that when `Matcher.group(*)` is called the results can be served from the cache.
Author
|
Any feedback on this pull request? |
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.
By default, RE2J does not resolve all the groups when performing a match operation, rather it only resolves groups when
Matcher.group(*)is called. This results in input being processed twice. Once during find() and then again during group(*). This increase the latency whenMatcher.find()andMatcher.group(*)are called in succession.This Pull Request attempts to reduce the latency by half by resolving the groups when
Matcher.find()is called, such that groups can be served from cache whenMatcher.group(*)is called.We can clearly see from the following benchmark tests that when
resolveGroups == true(When the groups are resolved duringfind()) and whensuccessMatch==ture(When the patterns are matched) for binary data we are seeing 0.609 ms/op vs 1.147 ms/op, providing 47% latency gain. Similarly, when thesuccessMatch==false(When there are no matching patterns) we are only seeing 4% regression (0.332 ms/op vs 0.319 ms/op). When string is used as the input, resolving groups duringfind()seems to outperform in all cases.As there are use cases only
Matcher.find()being called, and in such cases resolving groups can be an overkill, therefore I have enabled this optimization via a flag so we can tap into this optimization only when it's needed.Please provide your feedback on the pull request. I'm happy to make necessary changes to get this optimization merged.