Skip to content

[C++][Compute] Cache substring and regex matchers across invocations in scalar string kernels #53159

Open

Description

@ishaaaan17

Describe the enhancement requested

description

in cpp/src/arrow/compute/kernels/scalar_string_ascii.cc, the MatchSubstring kernels (match_substring, starts_with, ends_with, match_substring_regex and match_like) rebuild their matcher on every call to Exec.

for regex matchers that means the RE2 DFA gets recompiled for every batch or chunk in a stream or chunked array. for plain matchers it reallocates and rebuilds the Knuth-Morris-Pratt prefix table each batch.

both MatchSubstring<Type, Matcher>::Exec and MatchSubstring<Type, RegexSubstringMatcher>::Exec already carry a maintainer comment about this:
// TODO Cache matcher across invocations (for regex compilation)

proposed solution

replace OptionsWrapper<MatchSubstringOptions> with a dedicated MatchSubstringState. it lazily builds the matcher once and keeps the compiled or precomputed result in the KernelState, so later invocations reuse it.

Component(s)

C++

Activity

  1. added a commit that references this issue on Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions