Req #19697 [Asn]: calling str_replace unneeded uses too much memory
| From: | alan at roojs dot com | Date: | Sun, 11 Nov 2012 13:39:45 +0000 |
| Subject: | Req #19697 [Asn]: calling str_replace unneeded uses too much memory | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-9320@lists.php.net to get a copy of this message | ||
Edit report at https://pear.php.net/bugs/bug.php?id=19697&edit=1
ID: 19697
Updated by: alan@roojs.com
Reported By: michiel at ingoedebanen dot nl
Summary: calling str_replace unneeded uses too much memory
Status: Assigned
Type: Feature/Change Request
Package: DB_DataObject
Operating System: Linux
Package Version: 1.10.0
PHP Version: 5.3.13
Assigned To: alan_k
Roadmap Versions:
New Comment:
Commited - with slight mods - don't forget strpos can return '0' which
will evaluate as
false..
Previous Comments:
------------------------------------------------------------------------
[2012-11-10 00:13:29] doconnor
-Assigned To:
+Assigned To: alan_k
Thanks for the patch!
------------------------------------------------------------------------
[2012-11-10 00:12:45] doconnor
-Type: Bug
+Type: Feature/Change Request
------------------------------------------------------------------------
[2012-11-09 12:47:15] leening
Added #patch bug:19697;patch:DataObject.php.diff;revision:1352465235;.
------------------------------------------------------------------------
[2012-11-09 12:46:27] leening
Description:
------------
str_replace is called twice in both fetch() and fetchrow()
this is done for all keys in the result, even though they might not
contain a '.' or a ' '
since str_replace is memory expensive (consumes it), it is better to
check if the str_replace is actually needed by doing a strpos()
Test script:
---------------
The test was performed with xdebug (tracing memory usage) when
retrieving around 300-500 rows using 5 different kinds of classes.
Consider the following output:
before patch:
function #calls time memory
-----------------------------------------------
str_replace 172389 4.7536 110539952
after patch:
function #calls time memory
-----------------------------------------------
str_replace 13120 0.3583 4722288
Expected result:
----------------
That str_replace would not have consumed so much memory, but it really
adds up when you call it 170k times
------------------------------------------------------------------------
--
Edit this bug report at https://pear.php.net/bugs/bug.php?id=19697&edit=1