rfc:tsrmls-fetch-reduction
This is an old revision of the document!
Request for Comments: TSRMLS_FETCH() reduction
- Version: 1.0
- Date: 2010-09-09
- Author: Felipe Pena felipe@php.net
- Status: Under Discussion
Introduction
The purpose of RFC is to show a way to reduce several function call by avoiding useless TSRMLS_FETCH() usage on ZTS.
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.
| Current function/macro | New function/macro |
|---|---|
| emalloc | emallocts |
| ecalloc | ecallocts |
| pemalloc | pemallocts |
| erealloc | ereallocts |
| efree | efreets |
| estrdup | estrdupts |
| estrndup | estrndupts |
| ALLOC_INIT_ZVAL | ALLOC_INIT_ZVAL_TS |
| SEPARATE_ZVAL | SEPARATE_ZVAL_TS |
| SEPARATE_ZVAL_IF_NOT_REF | SEPARATE_ZVAL_IF_NOT_REF_TS |
| SEPARATE_ZVAL_TO_MAKE_IS_REF | SEPARATE_ZVAL_TO_MAKE_IS_REF_TS |
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
Non-patched
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
Proposal and Patch
Changelog
2010-09-09: Started.
rfc/tsrmls-fetch-reduction.1284076490.txt.gz · Last modified: (external edit)