Re: RETURN micro optimization
| From: | Dmitry Stogov | Date: | Tue, 05 Apr 2016 12:14:08 +0000 |
| Subject: | Re: RETURN micro optimization | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92100@lists.php.net to get a copy of this message | ||
On 04/05/2016 12:04 PM, Derick Rethans wrote:
On Tue, 5 Apr 2016, Dmitry Stogov wrote:It doesn't take into account that "return $x;" might be used in global scope. Setting $x to NULL in this case isn't right, of course. Introducing another check would probably negate the effect of micro-optimization. So, ignore this for now, and sorry for noise. Thanks. Dmitry.I propose a micro optimization for RETURN statement. Currently "return $x" increments reference counter of $x, then in zend_leave_helper() we perform zval_ptr_dtor() on the same $x. The patch sets the original value of $x to null in first place, so zval_ptr_dtor() is not going to be called. https://gist.github.com/dstogov/36f68b206242a39691ac539c2fc85d40 the performance impact is invisible (0.1% less instruction retired on Wordpress). It breaks sapi/phpdbg/tests/breakpoints_005.phpt, but this is probably not a big deal. BTW: this change may affect debuggers in some other way.I'd like to know why this breaks before saying something. It'd be a PITA if this micro optimisation wouldn't actually do a lot performance wise, but makes some debugging not possible. Actually, the patch has a bug.
cheers, Derick