rfc:tsrmls-fetch-reduction
Request for Comments: TSRMLS_FETCH() reduction
- Version: 1.0
- Date: 2010-09-09
- Author: Felipe Pena felipe@php.net, Pierre Alain Joye pajoye@php.net
- Status: Under implementation
Introduction
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
See below some macros/functions will be added by the patch.
Current function/macro | New function/macro |
---|---|
emalloc | emalloc2 |
ecalloc | ecalloc2 |
pemalloc | pemalloc2 |
erealloc | erealloc2 |
efree | efree2 |
estrdup | estrdup2 |
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
Zend/bench.php
Zend/bench.php | Patched | Current |
---|---|---|
simple | 0.487 | 0.562 |
simplecall | 1.697 | 1.971 |
simpleucall | 1.827 | 2.152 |
simpleudcall | 1.879 | 2.198 |
mandel | 1.950 | 2.286 |
mandel2 | 3.001 | 3.719 |
ackermann(7) | 1.426 | 1.874 |
ary(50000) | 0.260 | 0.256 |
ary2(50000) | 0.201 | 0.239 |
ary3(2000) | 1.506 | 1.758 |
fibo(30) | 5.065 | 5.618 |
hash1(50000) | 0.335 | 0.364 |
hash2(500) | 0.295 | 0.369 |
heapsort(20000) | 0.791 | 0.925 |
matrix(20) | 0.697 | 0.765 |
nestedloop(12) | 0.921 | 0.976 |
sieve(30) | 1.077 | 1.146 |
strcat(200000) | 0.130 | 0.148 |
Total | 23.547 | 27.328 |
Zend/microbench.php
Patched
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->x 2.161 1.351 $this->x = 0 3.719 2.909 $this->x += 2 1.863 1.053 ++$this->x 1.547 0.737 --$this->x 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
Current (trunk)
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->x 2.260 1.462 $this->x = 0 4.357 3.559 $this->x += 2 2.006 1.208 ++$this->x 1.658 0.860 --$this->x 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
Patch
Changelog
2010-09-09: Started.
rfc/tsrmls-fetch-reduction.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1