From:             yoarvi at gmail dot com
Operating system: Solaris 5.10 (SPARC)
PHP version:      6SVN-2009-11-20 (SVN)
PHP Bug Type:     Performance problem
Bug description:  [PATCH] - Using #defines to improve the performance of the 
TSRMG macro

Description:
------------
When compiled for multi-threaded (#ifdef ZTS ) operation, the various
subsystems in PHP use dynamically allocated (ts_allocate_id)
identifiers to index into the thread-local storage for each subsystem.
These dynamically allocated ids are used by macros such as CG, EG, PG,
AG.

The TSRMG macro is defined as:
#define TSRMG(id, type, element)        (((type) (*((void ***)
tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)

The PG macro is defined as:
# define PG(v) TSRMG(core_globals_id, php_core_globals *, v)

where core_globals_id is
extern PHPAPI int core_globals_id;

cc -E of
        PG(connection_status) = PHP_CONNECTION_ABORTED;
translates to:
 (((php_core_globals *) (*((void ***)
tsrm_ls))[((core_globals_id)-1)])->connection_status) = 1;

and cc -S of the same code results in:
        .loc 1 108 0
        movl    %ebx, %eax
        subl    core_globals_id, %eax
        movl    (%esi), %edx
        sall    $2, %eax
        negl    %eax
        movl    (%edx,%eax), %eax
        movw    $1, 144(%eax)

I used fixed IDs instead of dynamically allocated ones and noticed a
decent improvement in performance (few percentage points) when
running a web-based ecommerce-site workload on SPARC CMT hardware.

With my changes the PG macro is defined as:
# define PG(v) TSRMG(CORE_GLOBALS_ID, php_core_globals *, v)

#define CORE_GLOBALS_ID                                 10

and core_globals_id is
extern PHPAPI const ts_rsrc_id core_globals_id;

cc -E of the same line of code translates to:
 (((php_core_globals *) (*((void ***)
tsrm_ls))[((10)-1)])->connection_status) = 1;

cc -S (my version):
        .loc 1 108 0
        movl    (%eax), %eax
        movl    36(%eax), %eax
        movw    $1, 144(%eax)

The relevant discussion can be found here:
http://marc.info/?l=php-internals&m=125742200330841&w=2

Reproduce code:
---------------
The following patch implements this and incorporates the feedback received
on internals: 

http://bitbucket.org/arvi/arviq/src/tip/arvi-16-ts_allocate_reserved_id

Expected result:
----------------
Improved performance when PHP is compiled with support for
multi-threading.


-- 
Edit bug report at http://bugs.php.net/?id=50238&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=50238&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=50238&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=50238&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=50238&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=50238&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=50238&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=50238&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=50238&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=50238&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=50238&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=50238&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=50238&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=50238&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=50238&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=50238&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=50238&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=50238&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=50238&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=50238&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=50238&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=50238&r=mysqlcfg

Reply via email to