neilconway commented on code in PR #20295:
URL: https://github.com/apache/datafusion/pull/20295#discussion_r2796576755


##########
datafusion/functions/src/unicode/strpos.rs:
##########
@@ -179,6 +180,31 @@ fn strpos(args: &[ArrayRef]) -> Result<ArrayRef> {
     }
 }
 
+/// Find `needle` in `haystack` using `memchr` to quickly skip to positions
+/// where the first byte matches, then verify the remaining bytes. Using
+/// string::find is slower because it has significant per-call overhead that
+/// `memchr` does not, and strpos is often invoked many times on short inputs.
+/// Returns a 1-based position, or 0 if not found.
+/// Both inputs must be ASCII-only.
+fn find_ascii_substring(haystack: &[u8], needle: &[u8]) -> usize {

Review Comment:
   Thanks for the suggestion! When I tried using `memmem::find()`, it was 
substantially slower -- presumably because it incurs some per-call overhead 
(I'd imagine setting up lookup tables etc.) that `memchr` does not.
   
   I'd like to explore optimizing the (common) case where `strpos()` is invoked 
with a constant substring; in that case we could construct a `memmove::Finder` 
and use it for the entire input batch. But this PR is already a significant win 
so my thought was to defer that to a subsequent PR.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to