Re: Analysis of property visibility, immutability, a nd cloning proposals
| From: | Larry Garfield | Date: | Wed, 30 Dec 2020 20:37:58 +0000 |
| Subject: | Re: Analysis of property visibility, immutability, a nd cloning proposals | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112685@lists.php.net to get a copy of this message | ||
On Wed, Dec 30, 2020, at 2:16 PM, Olle Härstedt wrote:
> > Ok. You have a benchmark for this? I can make one otherwise, for the query
> > example.
> >
> > It worries me a little that immutablility is pushed into the ecosystem as a
> > silver bullet. Main reason functional languages are using it is because
> > ownership is a newer concept, so it hasn't been adapted as much.
>
> Tiny benchmark here:
>
> https://gist.github.com/olleharstedt/eaaf1dd40be541f84aa0f3954a0ea54a
>
> Running this on my ARM machine with PHP 7.2 gives ~1.2s for the
> immutable loop, ~0.35s for the mutable one, meaning immutability is
> ~3x as expensive performance wise. And this is for a SMALL object - I
> suspect the performance hit will grow the bigger the class gets (more
> properties to clone). Correct me if I'm wrong. :/
That's not a valid benchmark; it's comparing cloning and method invocation against just
property sets. The method calls are chewing up most of the time there.
Here's a more fair comparison on my laptop: https://gist.github.com/Crell/848568124e25c8c83fc4da5455063bab
Which is only ~20% slower. And that's when dealing with very small numbers, so in most cases
you're unlikely to notice a difference unless you really are iterating over something a million
times.
I also tossed some big string properties into the class, and while the total time went up a bit the
ratio between the two stayed about the same.
--Larry Garfield