yutianjiang39 opened a new pull request, #12529:
URL: https://github.com/apache/arrow-rs/pull/12529

   # Which issue does this PR close?
   
   Closes #11083.
   
   # Rationale for this change
   
   When a pattern column repeats, `regexp_is_match` reuses 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 single `entry` lookup 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_pattern` to 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.
   
   | Flags | Baseline, 64 rows | Baseline, 8,192 rows | Patched, 64 rows | 
Patched, 8,192 rows |
   |---|---:|---:|---:|---:|
   | None | 143 | 8,271 | 78 | 78 |
   | Repeated `i` | 173 | 8,301 | 110 | 110 |
   
   Benchmark 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):
   
   | Input | Flags | Baseline | Patched | Change |
   |---|---|---:|---:|---:|
   | constant | none | 2.05 ms | 1.44 ms | −29.6% |
   | constant | `i` | 3.93 ms | 2.26 ms | −42.3% |
   | random, nullable | none | 1.98 ms | 1.28 ms | −35.2% |
   | random, nullable | `i` | 3.74 ms | 1.90 ms | −49.0% |
   
   The gain comes from no longer building an owned `String` per row before the 
cache lookup (and, with flags, no per-row `format!`), 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`, `LargeUtf8` and `Utf8View`. They check 
the same pattern with different flags, null inputs, empty patterns and compile 
errors, including `Some("")` flags. These cases pass on both the baseline and 
the patch. All 201 `arrow-string` unit 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_match` and its cache 
lasts for one call. Matching results, errors and the public API stay the same.
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to