Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pool a matcher per thread #76

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

headius
Copy link
Member

@headius headius commented Oct 10, 2023

Matching is a leaf operation, so we can pool a matcher per thread to avoid the cost of constructing and initializing the entire matcher for each string.

This patch does eliminate all object creation in typical usage, reusing all objects and expecting users to pull match data out of them before using the regex again. However in benchmarks of a regex-heavy StringScanner-based CSV library (jruby/jruby#7604) the overhead of fetching and clearing the pooled matcher appears to hurt performance more than it helps to remove the allocations.

Matching is a leaf operation, so we can pool a matcher per thread
to avoid the cost of constructing and initializing the entire
matcher for each string.

This patch does eliminate all object creation in typical usage,
reusing all objects and expecting users to pull match data out of
them before using the regex again. However in benchmarks of a
regex-heavy StringScanner-based CSV library (jruby/jruby#7604) the
overhead of fetching and clearing the pooled matcher appears to
hurt performance more than it helps to remove the allocations.
@headius headius marked this pull request as draft October 10, 2023 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant