|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54249 extra CPU operation on each usage or E_* error types
Submitted: 2011-03-14 18:03 UTC Modified: 2011-03-14 23:49 UTC
From: amrnablus at gmail dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.3.5 OS: ALL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: amrnablus at gmail dot com
New email:
PHP Version: OS:


 [2011-03-14 18:03 UTC] amrnablus at gmail dot com
the way the errors are defined in zend_errors.h file makes an extra unneeded cpu shift (multiplication?) operation each time the error constant is used.

this is is from zend_errors.h:
#define E_ERROR                         (1<<0L)
if you printf( "%d" , E_ERROR ) the pre-processor will replace this line with
printf( "%d" , 1<<0L ) which will cause an uncalled for shit operation

Test script:
this script will cause a php E_NOTICE to be used, notice the (minor) diff in execution time when error definitions are changed

error_reporting( E_ALL );
for( $i=0 ; $i<10000000; $i++ ) {
        echo $x['a'];

Expected result:
no change to the output is a must


zend_errors (last revision 2011-03-14 17:03 UTC by amrnablus at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-14 18:31 UTC]
-Status: Open +Status: Bogus
 [2011-03-14 18:31 UTC]
I think you are missing a few pieces here on how compilers work. Yes, there is a 
preprocessor, but there is also a precompiler. The assembly generated by your 
example looks like this:

    movl    $1, %esi
    leaq    LC0(%rip), %rdi
    xorl    %eax, %eax
    jmp _printf

That says, put 1 into esi, then call printf. That 1 came from 1<<0L. The 
precompiler is smart enough to notice that this is an absolute constant here.
 [2011-03-14 19:44 UTC] Jared dot Williams at ntlworld dot com
See constant folding.
 [2011-03-14 23:49 UTC] amrnablus at gmail dot com
woops. Thanks guy, my bad.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 30 07:01:30 2024 UTC