Repository navigation
GH-53159: [C++][Compute] Cache substring and regex matchers across invocations in scalar string kernels - #53160
Open
ishaaaan17 wants to merge 1 commit into
Open
ishaaaan17 wants to merge 1 commit into
ishaaaan17 wants to merge 1 commit into
Conversation
…oss invocations in scalar string kernels
|
|
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.
rationale for this change
in
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc, the string matching kernels (match_substring,starts_with,ends_with,match_substring_regexandmatch_like) rebuild their matcher on every call toExec. for regex matchers that means the RE2 DFA is recompiled for every batch in a stream or chunked array. plain matchers reallocate and rebuild the Knuth-Morris-Pratt prefix table each time.this also closes out the existing todo in
MatchSubstring:// TODO Cache matcher across invocations (for regex compilation).what changes are included in this PR?
OptionsWrapper<MatchSubstringOptions>with aMatchSubstringState : public KernelStatethat caches the plain and regex matchers.MatchSubstringState::Get(ctx)so other kernels and tests that use the old accessor still work.PlainSubstringMatcher,PlainStartsWithMatcher,PlainEndsWithMatcherandRegexSubstringMatchernow reuse their compiled matchers across batches.MatchLikelooks at the SQL LIKE pattern and sets up the converter state once, instead of once per batch.clang-format.are these changes tested?
yes, by the existing kernel tests in
cpp/src/arrow/compute/kernels/scalar_string_test.cc. they run the matching kernels over chunks, slices and scalars throughCheckScalarUnary.are there any user-facing changes?
no public api changes.
was ai used for this PR?
in line with the ai generation guidelines, here is how ai was used.
pr code and description written by:
reviewed before submission by:
i used an llm assistant to look at different ways of caching the matchers and to draft the first version of the changes. i then went through and reworked the design myself, checked that the old state accessors still work, made sure the options are stored safely, and formatted the code.