Assess acceptability of having php-ds into core

php.internals

Guilherme Blanco

10 years ago
Hi internals, PHP 7 leverages a lot the performance internally and many PHP applications in the wild. Much of these improvement came by experimentation through PHPNG and the usage of efficient data structures internally. This idea of performance improvements are crucial to handle more requests, reduce server overload, etc. However, what lacks in PHP is the exposure of more efficient, use case specific data structures, that could allow end users to easily improve performance of their applications, instead of using a general, multi-purpose data structure that we have as "array". Based on that (please keep in mind I haven't spoken with library author), I'd like assess the receptability of incorporating php-ds library into core. Library author wrote a good (and lengthy) article explaining his motivation and performance benchmarks around it. Here are the related links: Article: https://medium.com/@rtheunissen/efficient-data-structures-for-php-7-9dda7af674cd Extension: https://github.com/php-ds/extension Polyfill: https://github.com/php-ds/polyfill Tests: https://github.com/php-ds/tests Benchmark: https://github.com/php-ds/benchmarks Best regards,
-- Guilherme Blanco Lead Architect at E-Block

Levi Morrison

10 years ago
On Thu, May 12, 2016 at 7:27 PM, guilhermeblanco@gmail.com <guilhermeblanco@gmail.com> wrote:
> Hi internals, > > PHP 7 leverages a lot the performance internally and many PHP applications > in the wild. Much of these improvement came by experimentation through > PHPNG and the usage of efficient data structures internally. This idea of > performance improvements are crucial to handle more requests, reduce server > overload, etc. > > However, what lacks in PHP is the exposure of more efficient, use case > specific data structures, that could allow end users to easily improve > performance of their applications, instead of using a general, > multi-purpose data structure that we have as "array". > > Based on that (please keep in mind I haven't spoken with library author), > I'd like assess the receptability of incorporating php-ds library into core. > > Library author wrote a good (and lengthy) article explaining his motivation > and performance benchmarks around it. Here are the related links: > > Article: > https://medium.com/@rtheunissen/efficient-data-structures-for-php-7-9dda7af674cd > Extension: https://github.com/php-ds/extension > Polyfill: https://github.com/php-ds/polyfill > Tests: https://github.com/php-ds/tests > Benchmark: https://github.com/php-ds/benchmarks > > > Best regards, > > -- > Guilherme Blanco > Lead Architect at E-Block
I've actually been working on data structures for PHP for years. I'm really glad I haven't pushed for anything before PHP 7, as improvements there give much more control in the data structures which is needed. I can say that work in question is of fairly good quality, though it makes some design decisions that I disagree with. Notably I think the Hashable interface is inferior to asking for hash and equal functions. By forcing the objects to be Hashable or to use spl_object_hash you cannot put objects into Maps or Sets that do not implement the interface (if you need behavior other than spl_object_hash). Routinely this has been a problem of every collection style library I've used before: having to implement a given interface that is new means the majority of the objects you want to put into it do not implement the interface. Also, if we move forward with putting this into core then we need to solidify our namespace. We currently reserve `PHP` and `php` in the docs, but this is not enforced in the runtime. I would not want to put these structures into the global namespace because `Map`, `Set` and `Collection` are all very common names. In any case I encourage people to use the APIs if they are somewhat interested. There is a polyfill available so you can become familiar without installing the extension.

Pierre Joye

10 years ago
Hi On May 13, 2016 8:28 AM, "guilhermeblanco@gmail.com" < guilhermeblanco@gmail.com> wrote:
> > Hi internals, > > PHP 7 leverages a lot the performance internally and many PHP applications > in the wild. Much of these improvement came by experimentation through > PHPNG and the usage of efficient data structures internally. This idea of > performance improvements are crucial to handle more requests, reduce
server
> overload, etc. > > However, what lacks in PHP is the exposure of more efficient, use case > specific data structures, that could allow end users to easily improve > performance of their applications, instead of using a general, > multi-purpose data structure that we have as "array". > > Based on that (please keep in mind I haven't spoken with library author), > I'd like assess the receptability of incorporating php-ds library into
core.
> > Library author wrote a good (and lengthy) article explaining his
motivation
> and performance benchmarks around it. Here are the related links: > > Article: >
https://medium.com/@rtheunissen/efficient-data-structures-for-php-7-9dda7af674cd
> Extension: https://github.com/php-ds/extension > Polyfill: https://github.com/php-ds/polyfill > Tests: https://github.com/php-ds/tests > Benchmark: https://github.com/php-ds/benchmarks
I like this ext. Good work. However I am not a fan to include as is. Many duplicates with spl. And we know too well that (standard)pl is a kind of a mess as it gets everything possible without too much thoughts about consistent APIs or if it makes sense. Or if one part fits better in the engine directly. Adding yet another extension to achieve similar goals, even if it is better, is not going to help to improve the situation, in contrary. I would prefer to discuss each structure individually to see if we need it, where it should be and how it should be done from an api pov. Cheers Pierre

Larry Garfield

10 years ago
On 05/12/2016 08:27 PM, guilhermeblanco@gmail.com wrote:
> Hi internals, > > PHP 7 leverages a lot the performance internally and many PHP applications > in the wild. Much of these improvement came by experimentation through > PHPNG and the usage of efficient data structures internally. This idea of > performance improvements are crucial to handle more requests, reduce server > overload, etc. > > However, what lacks in PHP is the exposure of more efficient, use case > specific data structures, that could allow end users to easily improve > performance of their applications, instead of using a general, > multi-purpose data structure that we have as "array". > > Based on that (please keep in mind I haven't spoken with library author), > I'd like assess the receptability of incorporating php-ds library into core. > > Library author wrote a good (and lengthy) article explaining his motivation > and performance benchmarks around it. Here are the related links: > > Article: > https://medium.com/@rtheunissen/efficient-data-structures-for-php-7-9dda7af674cd > Extension: https://github.com/php-ds/extension > Polyfill: https://github.com/php-ds/polyfill > Tests: https://github.com/php-ds/tests > Benchmark: https://github.com/php-ds/benchmarks > > > Best regards,
I am all for more efficient and performant tools being available natively. However, the php-ds extension in particular, while it sounds very nice, is still missing what I believe are key collection-related operations, that is, set-level operations. The equivalents of array_map, array_filter, first(callable) (ie, the first item that passes a given callable condition), etc. are all extremely powerful collection-level, functional operations. We have array-based versions and have for many years, but having them on formal collections or objects has always been a sore point, and run into various road blocks of "arrays aren't objects", "but then we can't extend the set of operations", etc. The pipe syntax currently being discussed helps some, but it's not as clean as doing it natively. If we're going to improve the quality of our native collection tools, then a richer set of operations (for which there is a known list of common operations from most functional languages) needs to be part of that discussion. --Larry Garfield