[PR][php-src][#1048][master] - Optimize static-scalar-case switches
| From: | noreply@php.net | Date: | Thu, 12 Feb 2015 18:26:34 +0000 |
| Subject: | [PR][php-src][#1048][master] - Optimize static-scalar-case switches | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-2310@lists.php.net to get a copy of this message | ||
You can view the Pull Request on github:
https://github.com/php/php-src/pull/1048
Pull Request Description:
Optimizes a switch by the use of a jumptable. (when all the case values could be resolved at
compile-time, which is usually the case, especially now since self:: class constants are resolved at
compile time too)
Optimization is done on null, true, false, string and long.
Doubles are excluded due to the fact that they can't be keys in HashTables (would be nice if
they would though, but that's another discussion.)
There are a lot of comparisons necessary due to the loose comparisons of strings in PHP. (e.g. null
== "", false == "", but false == "0" and null != "0"); the
places to jump to are then stored in new
zend_switch_table structure.
Saving this structure (which is referenced by a Z_PTR()) will probably break with opcache, this then
needs further work if current patch is fine. Also op2 of ZEND_FIRST_CASE is moved inside that
structure.
This hack needed to be done because VM accepts max. two operands per opcode and I needed to move
this structure pointer into the HashTable to have it properly freed upon op_array dtor.
Also, optimization is only done in case there are 3 or more cases, else it'd not worth it.
It mainly brings performance gains in case of stateful parsers in PHP where you have a large switch
to jump to the different state handlers.