Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved collections performance in common use cases
This improves the performance of most collection methods sometimes by making it 100% faster compared to the previous implementation. The improvement is not for free, with this change we are giving up the lazyness feature (not iterate unless requested). The giving up of the feature only happens when the collection has been initialized with an array, as oposed to being initialized with another iterator or generator; and this is the reson I consider this change a safe one. For the curious, the improvement comes from the (sad) fact that calling functions in php is extremenly expensive, specially when using iterators since each iteration will call at least 4 functions (valid, next, current, key). This becomes even worse as `IteratorIterator` does not have any optimizations, so for each wrapped iterator, the number of functions is multiplied by 2 for each iteration. The change proposed here will unwrap nested iterators as much as possible to avoid the function call explosion, and in some (safe) cases, will iterator the collection immediately as an array before wrapping it again in an iterator. I was inspired by Haskell when implementing this, as the language is lazy by default, but the compiler optimizes the cases where code is safe to be called strictly. Thats is called strictness analysis.
- Loading branch information
Showing
7 changed files
with
479 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.