Re: Apply substr() optimization to array_slice()
| From: | Nikita Popov | Date: | Fri, 27 Oct 2017 16:10:07 +0000 |
| Subject: | Re: Apply substr() optimization to array_slice() | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-100969@lists.php.net to get a copy of this message | ||
On Fri, Oct 27, 2017 at 4:16 PM, Sara Golemon <pollita@php.net> wrote:
> On Fri, Oct 27, 2017 at 8:12 AM, Benjamin Coutu <ben.coutu@zeyos.com>
> wrote:
> > Now, array_slice() could be optimized similarly, but currently
> > (unless the resulting array is expected to be empty) we always
> > create a new array no matter if we actually have to.
> >
> Pushed, with an additional escape hatch for vector-like arrays (which
> are implicitly like preserve_keys). In the future though, please use
> the PR process. Thanks.
>
Unfortunately these optimizations are subtly incorrect in the current form,
because arrays have a bunch of additional hidden state. See
https://bugs.php.net/bug.php?id=75433 for a (not
yet fixed) issue that
resulted from similar optimizations in 7.2. We'll have to review all the
places where we apply optimizations like these and make sure that we're not
introducing incorrect behavior wrt the next free element or internal array
pointer.
Nikita