FAQ
Edit report at https://pear.php.net/bugs/bug.php?id=19697&edit=1

ID: 19697
Updated by: daniel.oconnor@gmail.com
Reported By: michiel at ingoedebanen dot nl
Summary: calling str_replace unneeded uses too much memory
Status: Open
-Type: Bug
+Type: Feature/Change Request
Package: DB_DataObject
Operating System: Linux
Package Version: 1.10.0
PHP Version: 5.3.13
Roadmap Versions:
New Comment:

-Type: Bug
+Type: Feature/Change Request



Previous Comments:
------------------------------------------------------------------------

[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

------------------------------------------------------------------------

Search Discussions

  • Daniel Oconnor at Nov 10, 2012 at 12:13 am
    Edit report at https://pear.php.net/bugs/bug.php?id=19697&edit=1

    ID: 19697
    Updated by: daniel.oconnor@gmail.com
    Reported By: michiel at ingoedebanen dot nl
    Summary: calling str_replace unneeded uses too much memory
    Status: Open
    Type: Feature/Change Request
    Package: DB_DataObject
    Operating System: Linux
    Package Version: 1.10.0
    PHP Version: 5.3.13
    -Assigned To:
    +Assigned To: alan_k
    Roadmap Versions:
    New Comment:

    -Assigned To:
    +Assigned To: alan_k
    Thanks for the patch!


    Previous Comments:
    ------------------------------------------------------------------------

    [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

    ------------------------------------------------------------------------
  • Alan at Nov 11, 2012 at 1:39 pm
    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

    ------------------------------------------------------------------------
  • Alan at Nov 11, 2012 at 1:39 pm
    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

    ------------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedNov 10, '12 at 12:12a
activeNov 11, '12 at 1:39p
posts4
users2
websitepear.php.net

2 users in discussion

Daniel Oconnor: 2 posts Alan: 2 posts

People

Translate

site design / logo © 2022 Grokbase