Repository navigation
Contrib/issue 11083 - #12529
Open
yutianjiang39 wants to merge 2 commits into
Open
Contrib/issue 11083#12529yutianjiang39 wants to merge 2 commits into
yutianjiang39 wants to merge 2 commits into
Conversation
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.
Which issue does this PR close?
Closes #11083.
Rationale for this change
When a pattern column repeats,
regexp_is_matchreuses the compiled regex but still copies the pattern string on every cache hit. With flags, it also rebuilds the flag prefix for each lookup.What changes are included in this PR?
The array kernel now borrows its cache keys from the input columns. The loop without flags looks up
&str. The loop with flags looks up(&str, Option<&str>). Each uses a singleentrylookup and only compiles on a miss. A present flag gets its prefix at that point, even when the pattern is empty.The first commit adds the repeated-pattern benchmark so it can run against the original kernel and the optimized kernel. Run
cargo bench -p arrow --features test_utils --bench regexp_kernels -- regexp_is_match/repeated_patternto compare constant and random nullable inputs, with and without flags.Are these changes tested?
The allocation check counts allocations on the calling thread during one kernel call with two alternating patterns. Adding 8,128 rows cost one allocation per extra row on the baseline. With the patch, both counts stayed flat.
iBenchmark results from
cargo bench -p arrow --features test_utils --bench regexp_kernels -- regexp_is_match/repeated_pattern, with the first commit as the baseline (Linux, 4 vCPU AMD EPYC 9K65, 65,536 rows):iiThe gain comes from no longer building an owned
Stringper row before the cache lookup (and, with flags, no per-rowformat!), which matches the allocation counts above. The flags path gains more because it used to format a new string for every row. None of the measured inputs got slower.The allocation check runs separately because it installs a global allocator. The PR includes unit tests for
Utf8,LargeUtf8andUtf8View. They check the same pattern with different flags, null inputs, empty patterns and compile errors, includingSome("")flags. These cases pass on both the baseline and the patch. All 201arrow-stringunit tests, 10 doctests and lint checks passed with the patch.Are there any significant user-facing changes?
The optimization applies only to array/array
regexp_is_matchand its cache lasts for one call. Matching results, errors and the public API stay the same.