Re: [PHP-DEV] Request for couple memory optimized array improvements

2020-09-01 Thread Josh Bruce
That’s interesting as I haven’t played with iterates and generators much. If the iterator can’t take an iterable, the idea of something like __toArray seems way more convenient: https://wiki.php.net/rfc/to-array Cheers, Josh > On Aug 31, 2020, at 4:39 PM, Michael Voříšek - ČVUT FEL > wrote:

Re: [PHP-DEV] Request for couple memory optimized array improvements

2020-08-31 Thread tyson andre
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

Re: [PHP-DEV] Request for couple memory optimized array improvements

2020-08-31 Thread John Bafford
Hi Riikka, > On Aug 31, 2020, at 14:13, Riikka Kalliomäki > wrote: > > A common pattern that I've seen that could dearly use PHP internal > optimization, if possible, would be: > > foreach (array_keys($array) as $key) { > } I have a draft RFC (https://wiki.php.net/rfc/foreach_void) and patch

Re: [PHP-DEV] Request for couple memory optimized array improvements

2020-08-31 Thread Michael Voříšek - ČVUT FEL
I would highly prefer php optimalization for it. ArrayKeysIterator can not even used if the input is iterable instead of pure array. With kind regards / Mit freundlichen Grüßen / S přátelským pozdravem, Michael Voříšek On 31 Aug 2020 23:31, Max Semenik wrote: On Mon, Aug 31, 2020 at 11:53 PM

Re: [PHP-DEV] Request for couple memory optimized array improvements

2020-08-31 Thread Max Semenik
On Mon, Aug 31, 2020 at 11:53 PM Michael Voříšek - ČVUT FEL < voris...@fel.cvut.cz> wrote: > Optimizing foreach (array_keys($arr) as $k) is very important, not only > because of memory, but because of speed when not all elements needs to > be iterated, like: > > foreach (array_keys($arr) as $k) {

Re: [PHP-DEV] Request for couple memory optimized array improvements

2020-08-31 Thread Michael Voříšek - ČVUT FEL
Optimizing foreach (array_keys($arr) as $k) is very important, not only because of memory, but because of speed when not all elements needs to be iterated, like: foreach (array_keys($arr) as $k) { if ($k some condition) { break; } } please, can someone send a PR for this?

Re: [PHP-DEV] Request for couple memory optimized array improvements

2020-08-31 Thread Olle Härstedt
NB: You have SplFixedArray which can cover some use-cases. On Mon, 31 Aug 2020, 20:48 Markus Fischer, wrote: > On 31.08.20 20:13, Riikka Kalliomäki wrote: > > Another similar problem with creating array copies is the detection of > > "indexed" arrays (as opposed to associative arrays). > > I'm l

Re: [PHP-DEV] Request for couple memory optimized array improvements

2020-08-31 Thread Markus Fischer
On 31.08.20 20:13, Riikka Kalliomäki wrote: Another similar problem with creating array copies is the detection of "indexed" arrays (as opposed to associative arrays). I'm looking forward to an answer from someone proficient in this area because _I think_ the engine _internally_ keeps track of

[PHP-DEV] Request for couple memory optimized array improvements

2020-08-31 Thread Riikka Kalliomäki
Hello, For the past couple years I've been working with a PHP code base that at times deals with quite large payloads memory wise. This has made me pay more attention to some array operations in PHP that are rather frustrating to deal with in userland PHP, but could perhaps be optimized more in PH