Re: Improved performance of array_maerge() and func_get_args()

From: Date: Wed, 23 Oct 2013 19:23:43 +0000
Subject: Re: Improved performance of array_maerge() and func_get_args()
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
No. the array_merge() patch doesn't change the algorithm.
We just discovered that array_merge() makes a copy of each element of each
array before the actual merging, and in case it's an array or object, it
may take significant time, but this copying is absolutely useless. The
patch just remove it.

Thanks. Dmitry.


On Wed, Oct 23, 2013 at 10:10 PM, Patrick ALLAERT <[email protected]>wrote:

> 2013/10/23 Dmitry Stogov <[email protected]>:
> > Hi,
> >
> > I'm proposing two simple patches that eliminate a lot of useless zval
> > copying.
> > For example they remove only about 800 calls to zend_hash_copy() (25%) on
> > each request to wordpress-3.6.0 home page and make it 2-4% faster.
> >
> > It's not a questions about master branch, but I think it is also safe to
> > commit them into PHP-5.4 and PHP-5.5.
> >
> > Any objections?
> >
> > https://gist.github.com/dstogov/7117623
> >
> > https://gist.github.com/dstogov/7117649
> >
> > Thanks. Dmitry.
>
> That sounds really good.
>
> Note that in many performance investigations I made, array_merge() was
> often one of the cause of some unnecessary overhead, however, most of
> the times this function was used was in fact to merge arrays that were
> in fact *hashes* (dictionary, map,...) and not really *arrays*. In
> those cases, the performance fix is simply to use "$y + $x" instead of
> "array_merge($x, $y).
>
> Are all those array_merge() of wordpress really made to merge *arrays*
> rather than *hashes*?
>
> Is the gain constant for all cases of array_merge(), with numeric
> indices vs string ones?
>
> Patrick
>


Thread (14 messages)

« previous php.internals (#69817) next »