در تاریخ دوشنبه ۳۱ اوت ۲۰۲۶، ۱۹:۲۲ Kamil Tekiela <[email protected]>
نوشت:

> > 1. Short-circuiting vs Allocation: Using `array_filter` processes the
> entire array and allocates a new filtered array in memory, whereas a
> dedicated C implementation (`array_str_contains` / short-circuit loop)
> immediately returns `true` on the first match without extra allocations.
>
> What do you mean? I thought the purpose of the new function was to
> return a list with all matching entries? How could it short-circuit on
> the first match?
>
> > 2. Direct C-level loop: Bypassing the VM dispatch loop for each element
> gives noticeable gains, especially on larger datasets or hot paths.
>
> What kind of dispatch are you talking about here? Do you mean calling
> str_contains() for each row?
>

--------

Hi Kamil,

Thanks for pointing that out, and apologies for the confusion in my
previous wording!

1. You are totally right: the function returns an array of matched elements
(filtering), so it does iterate through the full array rather than
short-circuiting. My previous note mistakenly mixed up the behavior with an
existence-check helper like array_any(). The main benefit here is avoiding
userland closure invocation overhead for each element.

2. Exactly, by VM dispatch / call overhead, I meant the overhead of
repeatedly calling userland closures or functions (like invoking
str_contains() per element via array_filter()) compared to running a native
C loop using php_memnstr directly.

Best regards,
Sepehr

Reply via email to