implode() speedup in PHP4

php.internals

Alexander Valyalkin

21 years ago
I've posted patch last summer http://www.zend.com/zend/week/pat/pat5.txt which imporves performance of implode() function in PHP4, but nobody doesn't commit it yet. Can anybody explain the reason?
-- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

Christian Stadler

21 years ago
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Alexander Valyalkin schrieb:
> I've posted patch last summer http://www.zend.com/zend/week/pat/pat5.txt > which imporves performance of implode() function in PHP4, but nobody > doesn't > commit it yet. Can anybody explain the reason?
After applying the change to ext/standard/string.c in PHP4 the following Test failed: Bug #22224 (implode changes object references in array) [ext/standard/tests/strings/bug22224.phpt] Regards, Christian Stadler -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCO0No9250Hcbf/3IRAndDAJ9H9iNnfa1CXegMHWgmyfR0S2QLhwCfSv3F 7pYwoZ8Y9NeFpzrMeuHxue8= =GtGF -----END PGP SIGNATURE-----

Alexander Valyalkin

21 years ago
> After applying the change to ext/standard/string.c in PHP4 the following > Test failed: > Bug #22224 (implode changes object references in array) > [ext/standard/tests/strings/bug22224.phpt] > > Regards, > Christian Stadler
I understood my fault. I didn't notice condition if (!(*ppzv)->is_ref) { } in convert_to_ex_master() macro. But compare execution time of the following test on PHP4 & PHP5: <? function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $t = getmicrotime(); $s = str_repeat('a', 1 << 24); $a = implode(",", array($s, $s)); echo getmicrotime() - $t; ?> I think, it will be good idea to fix such time wasting in PHP4.

Moriyoshi Koizumi

21 years ago
On 2005/03/19, at 3:41, Alexander Valyalkin wrote:
> > I've posted patch last summer > http://www.zend.com/zend/week/pat/pat5.txt > which imporves performance of implode() function in PHP4, but nobody > doesn't > commit it yet. Can anybody explain the reason?
Because convert_to_string_ex() modifies the content of every element that is not of string type. <?php $arrays = array(array(), array(), array()); var_dump(implode('', $arrays)); var_dump($arrays); ?> We already have an optimisation in the 5.x branches. I think it is appliable to the 4.3 branch. Moriyoshi

Derick Rethans

21 years ago
On Sat, 19 Mar 2005, Moriyoshi Koizumi wrote:
> <?php > $arrays = array(array(), array(), array()); > var_dump(implode('', $arrays)); > var_dump($arrays); > ?> > > We already have an optimisation in the 5.x branches. > I think it is appliable to the 4.3 branch.
4.3 is only for bugfixes! Derick
-- Derick Rethans http://derickrethans.nl | http://ez.no | http://xdebug.org

Moriyoshi Koizumi

21 years ago
On 2005/03/19, at 6:14, Derick Rethans wrote:
> On Sat, 19 Mar 2005, Moriyoshi Koizumi wrote: > >> <?php >> $arrays = array(array(), array(), array()); >> var_dump(implode('', $arrays)); >> var_dump($arrays); >> ?> >> >> We already have an optimisation in the 5.x branches. >> I think it is appliable to the 4.3 branch. > > 4.3 is only for bugfixes!
It didn't mean that the fix should be in the 4.3. What was it that excited you so much? :) Moriyoshi

Andi Gutmans

21 years ago
Just make sure that zval's which are isolated with convert_to_string_ex() are only used as read-only. At 09:41 PM 3/18/2005 +0300, Alexander Valyalkin wrote: