Req #19697 [Asn->Csd]: calling str_replace unneeded uses too much memory
| From: | alan at roojs dot com | Date: | Sun, 11 Nov 2012 13:39:52 +0000 |
| Subject: | Req #19697 [Asn->Csd]: calling str_replace unneeded uses too much memory | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-9321@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
+Status: Closed
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:
-Status: Assigned
+Status: Closed
This bug has been fixed in SVN.
If this was a documentation problem, the fix will appear on pear.php.net
by the end of next Sunday (CET).
If this was a problem with the pear.php.net website, the change should
be live shortly.
Otherwise, the fix will appear in the package's next release.
Thank you for the report and for helping us make PEAR better.
Previous Comments:
------------------------------------------------------------------------
[2012-11-11 13:39:44] alan_k
Commited - with slight mods - don't forget strpos can return '0' which
will evaluate as
false..
------------------------------------------------------------------------
[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