rfc:tsrmls-fetch-reduction

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:tsrmls-fetch-reduction [2010/09/09 23:13] – Update feliperfc:tsrmls-fetch-reduction [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 2: Line 2:
   * Version: 1.0   * Version: 1.0
   * Date: 2010-09-09   * Date: 2010-09-09
-  * Author: Felipe Pena <felipe@php.net> +  * Author: Felipe Pena <felipe@php.net>, Pierre Alain Joye <pajoye@php.net> 
-  * Status: Under Discussion+  * Status: Under implementation
  
 ===== Introduction ===== ===== Introduction =====
  
-The purpose of RFC is to show a way to reduce several function call by avoiding useless TSRMLS_FETCH() usage.+The purpose of RFC is to show a way to reduce several function call by avoiding useless TSRMLS_FETCH() usage on ZTS. Adding TSRMLS_CC to the memory allocation macros/function, hash api, zend_llist and streams.
  
 ===== Changes ====== ===== Changes ======
- 
-The main goal was to create a new version of each memory allocation function/macro where TSRMLS_FETCH() is not used, thus using these new functions/macros only when suitable avoiding to call the function that does thread id fetch. 
  
 See below some macros/functions will be added by the patch. See below some macros/functions will be added by the patch.
  
 ^ Current function/macro ^ New function/macro ^ ^ Current function/macro ^ New function/macro ^
-| emalloc          | emallocts    | +| emalloc          | emalloc2    | 
-| ecalloc          | ecallocts    | +| ecalloc          | ecalloc2    | 
-| pemalloc         pemallocts   | +| pemalloc         pemalloc2   | 
-| erealloc         ereallocts   | +| erealloc         erealloc2   | 
-| efree            | efreets      | +| efree            | efree2      | 
-| estrdup          | estrdupts    | +| estrdup          | estrdup2    | 
-| estrndup         estrndupts   |+| estrndup         estrndup2   |
  
 +===== Profiler =====
 +
 +Using cachegrind (//valgrind --tool=cachegrind --cachegrind-out-file=profile sapi/cli/php Zend/bench.php//) to see the improvement, we can see the follow differences:
 +
 +^ Function ^ Ir (Patched) ^ Ir (Current) ^
 +| pthread_getspecific | 498,129,021 | 1,269,764,085 |
 +| ts_resource_ex | 394,353,075 | 1,005,230,834 |
 +| efree | 459,940,754 | 840,217,602 |
 +
 +^ Ir Total (Patched) ^ Ir Total (Current) ^
 +| 42,537,064,394 | 44,080,331,320 |
 +
 +// Ir - Instruction read //
  
 ===== Benchmark ===== ===== Benchmark =====
 +
 +==== Zend/bench.php ====
  
 ^ Zend/bench.php    ^ Patched ^ Current ^ ^ Zend/bench.php    ^ Patched ^ Current ^
Line 48: Line 61:
 | Total             | 23.547 | 27.328 | | Total             | 23.547 | 27.328 |
  
 +==== Zend/microbench.php ====
 +
 +**Patched**
 +<code>
 +empty_loop         0.810
 +func()             3.588    2.778
 +undef_func()       3.775    2.965
 +int_func()         3.651    2.841
 +$x = self::$x      2.108    1.297
 +self::$x = 0       1.878    1.067
 +isset(self::$x)    1.676    0.865
 +empty(self::$x)    1.754    0.944
 +$x = Foo::$x       1.830    1.019
 +Foo::$x = 0        1.746    0.936
 +isset(Foo::$x)     1.543    0.733
 +empty(Foo::$x)     1.673    0.863
 +self::f()          3.764    2.954
 +Foo::f()           3.581    2.770
 +$x = $this->     2.161    1.351
 +$this->x = 0       3.719    2.909
 +$this->x += 2      1.863    1.053
 +++$this->        1.547    0.737
 +--$this->        1.665    0.855
 +$this->x++         1.524    0.714
 +$this->x--         1.532    0.722
 +isset($this->x)    1.726    0.915
 +empty($this->x)    1.891    1.081
 +$this->f()         4.151    3.341
 +$x = Foo::TEST     1.628    0.818
 +new Foo()         10.194    9.384
 +$x = TEST          1.327    0.517
 +$x = $_GET         2.167    1.357
 +$x = $GLOBALS['v'] 2.897    2.086
 +$x = $hash['v'   2.034    1.224
 +$x = $str[0]       5.311    4.500
 +------------------------
 +Total             80.712
 +</code>
  
 +**Current (trunk)**
 +<code>
 +empty_loop         0.798
 +func()             3.634    2.836
 +undef_func()       3.633    2.836
 +int_func()         3.896    3.099
 +$x = self::$x      2.129    1.332
 +self::$x = 0       1.945    1.148
 +isset(self::$x)    1.755    0.958
 +empty(self::$x)    1.660    0.863
 +$x = Foo::$x       1.986    1.189
 +Foo::$x = 0        1.769    0.971
 +isset(Foo::$x)     1.556    0.759
 +empty(Foo::$x)     1.750    0.953
 +self::f()          4.268    3.470
 +Foo::f()           3.874    3.077
 +$x = $this->     2.260    1.462
 +$this->x = 0       4.357    3.559
 +$this->x += 2      2.006    1.208
 +++$this->        1.658    0.860
 +--$this->        1.643    0.846
 +$this->x++         1.804    1.007
 +$this->x--         1.818    1.021
 +isset($this->x)    1.832    1.035
 +empty($this->x)    2.050    1.253
 +$this->f()         4.537    3.739
 +$x = Foo::TEST     1.804    1.006
 +new Foo()         10.702    9.904
 +$x = TEST          1.558    0.760
 +$x = $_GET         2.274    1.476
 +$x = $GLOBALS['v'] 3.105    2.307
 +$x = $hash['v'   1.939    1.141
 +$x = $str[0]       5.371    4.573
 +------------------------
 +Total             85.372
 +</code>
  
-===== Proposal and Patch =====+===== Patch =====
  
-Comming soon+http://felipe.ath.cx/diff/tsrmls-fetch-reduction.diff
  
 ===== Changelog ===== ===== Changelog =====
rfc/tsrmls-fetch-reduction.1284074029.txt.gz · Last modified: 2017/09/22 13:28 (external edit)