Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This branch has not been deployed
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.
Expanding a counted repetition materialises one copy of the subexpression per repetition before any program-size limit is consulted. A pattern such as
a{1000}repeated 30000 times coalesces into a single {30000000,30000000} repeat, and Simplify then allocates ~500 MB expanding it, even though the pattern can never compile: the program-size limit only applies later, in the compiler.max_memdoes not help either, for the same reason.Give Simplify() an optional expansion budget, counted in copies materialised while expanding repetitions, and fail the simplification (returning NULL, as the compiler already handles) once it would be exceeded. The compiler passes its own program-size limit, so patterns that could never compile are now rejected before the expansion allocates, while patterns that compile today keep compiling: each copy compiles to roughly one instruction, so the budget matches the limit it derives from.
Before/after (pattern
a{0,1000}repeated N times, peak RSS):N=600: 38.0 MB -> 37.9 MB (still compiles, unchanged)
N=700: 26.9 MB -> 3.8 KB (rejected fast)
N=10000: 162 MB -> 5.6 KB
N=30000: 478 MB, 2.21 s -> 9.0 KB, 0.01 s
A general-case variant (
a{0,1000}x30000) went from ~3.8 GB peak RSS to 9.0 KB. All re2 tests pass, including under ASan.