Professional Web Applications Themes

#40002 [NEW]: Try/Catch performs poorly - PHP Bugs

From: public at syranide dot com Operating system: Windows XP 32bit PHP version: 5.2.0 PHP Bug Type: Performance problem Bug description: Try/Catch performs poorly Description: ------------ Try/Catch-statements in PHP is performing rather poorly, main problem that seems to be that the Catch-clauses are always tried regardless of an exception being thrown or not. Although Try/Catch is pretty expensive (about twice of ), the worst part is that it scales linear with each Catch. Of course that might be very hard to not do and is not a problem, but the problem arises from the linear scaling followed by Catch-clauses always ...

  1. #1

    Default #40002 [NEW]: Try/Catch performs poorly

    From: public at syranide dot com
    Operating system: Windows XP 32bit
    PHP version: 5.2.0
    PHP Bug Type: Performance problem
    Bug description: Try/Catch performs poorly

    Description:
    ------------
    Try/Catch-statements in PHP is performing rather poorly, main problem that
    seems to be that the Catch-clauses are always tried regardless of an
    exception being thrown or not.

    Although Try/Catch is pretty expensive (about twice of ), the worst part
    is that it scales linear with each Catch.

    Of course that might be very hard to not do and is not a problem, but the
    problem arises from the linear scaling followed by Catch-clauses always
    impacting performance, regardless of an Exception being thrown or not.

    Reproduce code:
    ---------------
    $start = microtime(TRUE);

    class PHPException extends Exception {}

    for($i = 0; $i < 100000; $i++) {
    try {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    }

    echo microtime(TRUE) - $start;

    Expected result:
    ----------------
    Note that the above code is rather strupid in nature, but the result is
    the same regardless.

    From the above I would expect very similar performance to having only one
    Catch-clause (or to be more precise, that in the event of no exception
    being thrown performance is not linear to the number of Catch-clauses).

    Actual result:
    --------------
    (nothing useful)

    --
    Edit bug report at [url]http://bugs.php.net/?id=40002&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=40002&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=40002&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=40002&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=40002&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=40002&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=40002&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=40002&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=40002&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=40002&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=40002&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=40002&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=40002&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=40002&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=40002&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=40002&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=40002&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=40002&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=40002&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=40002&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=40002&r=mysqlcfg[/url]
    public at syranide dot com Guest

  2. #2

    Default #40002 [Opn]: Try/Catch performs poorly

    ID: 40002
    User updated by: public at syranide dot com
    Reported By: public at syranide dot com
    Status: Open
    Bug Type: Performance problem
    Operating System: Windows XP 32bit
    PHP Version: 5.2.0
    New Comment:

    Should've mentioned this in the report, but one reason behind that it
    should not scale linear is because just as well as adding more clauses
    you could instead just make one catch-all-clause.
    This clause internally matches exceptions (using is_a etc) and if none
    is matched then it is thrown again, which should have equal
    functionality, but more clauses does not affect performance if no
    exception is thrown.


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

    [2007-01-02 19:47:15] public at syranide dot com

    Description:
    ------------
    Try/Catch-statements in PHP is performing rather poorly, main problem
    that seems to be that the Catch-clauses are always tried regardless of
    an exception being thrown or not.

    Although Try/Catch is pretty expensive (about twice of ), the worst
    part is that it scales linear with each Catch.

    Of course that might be very hard to not do and is not a problem, but
    the problem arises from the linear scaling followed by Catch-clauses
    always impacting performance, regardless of an Exception being thrown
    or not.

    Reproduce code:
    ---------------
    $start = microtime(TRUE);

    class PHPException extends Exception {}

    for($i = 0; $i < 100000; $i++) {
    try {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    }

    echo microtime(TRUE) - $start;

    Expected result:
    ----------------
    Note that the above code is rather strupid in nature, but the result is
    the same regardless.

    From the above I would expect very similar performance to having only
    one Catch-clause (or to be more precise, that in the event of no
    exception being thrown performance is not linear to the number of
    Catch-clauses).

    Actual result:
    --------------
    (nothing useful)


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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40002&edit=1[/url]
    public at syranide dot com Guest

  3. #3

    Default #40002 [Opn->Asn]: Try/Catch performs poorly

    ID: 40002
    Updated by: [email]iliaaphp.net[/email]
    Reported By: public at syranide dot com
    -Status: Open
    +Status: Assigned
    Bug Type: Performance problem
    Operating System: Windows XP 32bit
    PHP Version: 5.2.0
    -Assigned To:
    +Assigned To: dmitry


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

    [2007-01-02 19:58:26] public at syranide dot com

    Should've mentioned this in the report, but one reason behind that it
    should not scale linear is because just as well as adding more clauses
    you could instead just make one catch-all-clause.
    This clause internally matches exceptions (using is_a etc) and if none
    is matched then it is thrown again, which should have equal
    functionality, but more clauses does not affect performance if no
    exception is thrown.

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

    [2007-01-02 19:47:15] public at syranide dot com

    Description:
    ------------
    Try/Catch-statements in PHP is performing rather poorly, main problem
    that seems to be that the Catch-clauses are always tried regardless of
    an exception being thrown or not.

    Although Try/Catch is pretty expensive (about twice of ), the worst
    part is that it scales linear with each Catch.

    Of course that might be very hard to not do and is not a problem, but
    the problem arises from the linear scaling followed by Catch-clauses
    always impacting performance, regardless of an Exception being thrown
    or not.

    Reproduce code:
    ---------------
    $start = microtime(TRUE);

    class PHPException extends Exception {}

    for($i = 0; $i < 100000; $i++) {
    try {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    }

    echo microtime(TRUE) - $start;

    Expected result:
    ----------------
    Note that the above code is rather strupid in nature, but the result is
    the same regardless.

    From the above I would expect very similar performance to having only
    one Catch-clause (or to be more precise, that in the event of no
    exception being thrown performance is not linear to the number of
    Catch-clauses).

    Actual result:
    --------------
    (nothing useful)


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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40002&edit=1[/url]
    iliaa@php.net Guest

  4. #4

    Default #40002 [Asn->Csd]: Try/Catch performs poorly

    ID: 40002
    Updated by: [email]dmitryphp.net[/email]
    Reported By: public at syranide dot com
    -Status: Assigned
    +Status: Closed
    Bug Type: Performance problem
    Operating System: Windows XP 32bit
    PHP Version: 5.2.0
    Assigned To: dmitry
    New Comment:

    Fixed in CVS HEAD and PHP_5_2.


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

    [2007-01-02 19:58:26] public at syranide dot com

    Should've mentioned this in the report, but one reason behind that it
    should not scale linear is because just as well as adding more clauses
    you could instead just make one catch-all-clause.
    This clause internally matches exceptions (using is_a etc) and if none
    is matched then it is thrown again, which should have equal
    functionality, but more clauses does not affect performance if no
    exception is thrown.

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

    [2007-01-02 19:47:15] public at syranide dot com

    Description:
    ------------
    Try/Catch-statements in PHP is performing rather poorly, main problem
    that seems to be that the Catch-clauses are always tried regardless of
    an exception being thrown or not.

    Although Try/Catch is pretty expensive (about twice of ), the worst
    part is that it scales linear with each Catch.

    Of course that might be very hard to not do and is not a problem, but
    the problem arises from the linear scaling followed by Catch-clauses
    always impacting performance, regardless of an Exception being thrown
    or not.

    Reproduce code:
    ---------------
    $start = microtime(TRUE);

    class PHPException extends Exception {}

    for($i = 0; $i < 100000; $i++) {
    try {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    catch(PHPException $e) {}
    }

    echo microtime(TRUE) - $start;

    Expected result:
    ----------------
    Note that the above code is rather strupid in nature, but the result is
    the same regardless.

    From the above I would expect very similar performance to having only
    one Catch-clause (or to be more precise, that in the event of no
    exception being thrown performance is not linear to the number of
    Catch-clauses).

    Actual result:
    --------------
    (nothing useful)


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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40002&edit=1[/url]
    dmitry@php.net Guest

Similar Threads

  1. Vector logos display poorly in PDF
    By BlockBird@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 5
    Last Post: July 20th, 05:34 PM
  2. Flash Player Performs Poorly for Win2003 Terminal ServerClients
    By ult_netsupport in forum Macromedia Flash Player
    Replies: 1
    Last Post: May 5th, 07:46 AM
  3. Vector hairlines printing poorly
    By Jouni_Weckman@adobeforums.com in forum Adobe Indesign Windows
    Replies: 4
    Last Post: July 7th, 02:34 PM
  4. Poorly copied doents
    By Mick in forum Adobe Photoshop Elements
    Replies: 1
    Last Post: August 17th, 10:19 PM
  5. Replies: 1
    Last Post: July 15th, 07:39 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139