Re: Request for couple memory optimized array improvements
| From: | tyson andre | Date: | Mon, 31 Aug 2020 23:21:38 +0000 |
| Subject: | Re: Request for couple memory optimized array improvements | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-111755@lists.php.net to get a copy of this message | ||
Hi Riikka Kalliomäki,
> Another similar problem with creating array copies is the detection of
> "indexed" arrays (as opposed to associative arrays). Particularly when
> dealing with JSON, it's a common need to detect if an array has keys
> from 0 to n-1 and in that order. My understanding is that at least in
> some cases this would be trivial and fast to tell internally in PHP,
> but the functionality is not exposed to userland.
>
> Current common practices include for example:
>
> array_keys($array) === range(0, count($array) - 1)
>
> Memory optimized way of dealing with this is via foreach, but it's
> quite cumbersome and again, you must not use array_keys in the
> foreach. The following example demonstrates that the worst case
> scenario triples the memory usage using range:
> https://3v4l.org/FiWdk
This was brought up in https://externals.io/message/109760#109795
there's a PR against php-src but there was some discussion about
whether php should strive to add an actual "list" type instead
and what it should be named - https://github.com/php/php-src/pull/4886
I'm fairly certain is_list() would have to go through the RFC process given
the proposals for alternate approaches or alternate names
Cheers,
- Tyson