Improve PCRE2 match performance for JIT and interpreted #13146
Merged
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 patch contains a number of individual steps that improve performance of PCRE2 matching greatly.
MatchContext
that is allocated only once and shared between all match executions. JIT stack is assigned via a callback which returns the appropriate thread-local stack. The callback won't be called if JIT is not used. This improve JIT performance.MatchData
per instance and thread. This avoids re-allocating the backtracking stack which improve interpreted performanceMatchData
does not leak outside the local scope, there's no need to allocate it with the GC.libpcre2
can manage its memory on its own and theMatchData
instances are handled in the bindings. This reduces GC pressure.Using the benchmark program from #13144 (comment), I get these results:
This shows a great improvement in match performance. The PCRE1 implementation is still significantly more performant in JIT mode (
matches?
).A factor for this could be that the PCRE1 bindings are not thread safe. I'll leave investigation into this as a follow-up and consider the main regression as resolved.
Resolves #13144