rfc:fast_zpp
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:fast_zpp [2014/05/28 14:08] – bwoebi | rfc:fast_zpp [2015/01/27 21:18] – dmitry | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2014-05-23 | * Date: 2014-05-23 | ||
* Author: Dmitry Stogov < | * Author: Dmitry Stogov < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 16: | Line 16: | ||
===== Proposal ===== | ===== Proposal ===== | ||
We propose an additional fast API for parameter parsing, that should be used for the most useful functions. The API is based on C macros that lead to inlining of optimized code directly into the body of internal function. | We propose an additional fast API for parameter parsing, that should be used for the most useful functions. The API is based on C macros that lead to inlining of optimized code directly into the body of internal function. | ||
+ | |||
+ | **We don't propose to remove the existing API, and would suggest to use fast API only for most often used functions to get performance boost.** | ||
I'll explain API on the following example: | I'll explain API on the following example: | ||
Line 36: | Line 38: | ||
The first code fragment is just taken from PHP_FUNCTION(array_slice), | The first code fragment is just taken from PHP_FUNCTION(array_slice), | ||
- | ZEND_PARSE_PARAMETERS_START() takes two arguments minimal and maximal parameters count. (In general, it's possible to avoid these arguments, but not for free. I'll explain it separate " | + | ZEND_PARSE_PARAMETERS_START() takes two arguments minimal and maximal parameters count. |
Z_PARAM_ARRAY() - takes the next argument as array, Z_PARAM_LONG - as long, Z_PARAM_OPTIONAL - tells that the remaining arguments are optional. | Z_PARAM_ARRAY() - takes the next argument as array, Z_PARAM_LONG - as long, Z_PARAM_OPTIONAL - tells that the remaining arguments are optional. | ||
Line 42: | Line 44: | ||
The new API covers all possibilities of the existing API. The following table shows the correspondence between old specifiers and new macros. | The new API covers all possibilities of the existing API. The following table shows the correspondence between old specifiers and new macros. | ||
- | ^ specifier ^ Fast ZPP API macro ^^ | + | ^ specifier ^ Fast ZPP API macro ^ args ^ |
| '' | | '' | ||
| a | Z_PARAM_ARRAY(dest) | | a | Z_PARAM_ARRAY(dest) | ||
Line 68: | Line 70: | ||
The effect of **!** and reference modifiers may be achieved using extended version of the same macros e.g. Z_PARAM_ZVAL_EX(dest, | The effect of **!** and reference modifiers may be achieved using extended version of the same macros e.g. Z_PARAM_ZVAL_EX(dest, | ||
- | |||
- | ==== Simpler Variation ==== | ||
- | |||
- | It's possible not to specify minimal and maximal arguments in ZEND_PARSE_PARAMETERS_START() macro, but it leads to some small performance degradation and possible inconsistent error messages when few constraint are broken at same time. For example the following code '' | ||
- | |||
- | '' | ||
- | |||
- | however the original PHP would emit | ||
- | |||
- | '' | ||
- | |||
- | This is not a common case. Actually, it breaks just 2 PHPT tests. | ||
- | So the penalties may be accepted in cost of usability. | ||
- | On the other hand these number need to be written just once... | ||
- | |||
- | ==== Alternative syntax (based on simpler variation) ==== | ||
- | |||
- | This syntax is a shorter alternative (for those who don't like too many lines for parameter parsing): | ||
- | |||
- | < | ||
- | zend_parse_parameters(Z_PARAM_ARRAY(input) Z_PARAM_LONG(offset) Z_PARAM_OPTIONAL Z_PARAM_ZVAL(z_length) Z_PARAM_BOOL(preserve_keys)) | ||
- | </ | ||
- | |||
- | or, in the special case where we'd need special failure handling: | ||
- | |||
- | < | ||
- | zend_parse_parameters_ex(Z_PARAM_ARRAY(input) Z_PARAM_LONG(offset) Z_PARAM_OPTIONAL Z_PARAM_ZVAL(z_length) Z_PARAM_BOOL(preserve_keys), | ||
- | /* handle failure; */ | ||
- | return; | ||
- | }) | ||
- | </ | ||
==== Performance Evaluation ==== | ==== Performance Evaluation ==== | ||
Line 107: | Line 78: | ||
| phpng | 5, | | phpng | 5, | ||
| phpng + fast_zpp | | phpng + fast_zpp | ||
- | | phpng + simple variation | 4, | ||
Line 118: | Line 88: | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | This proposal is targeted to phpng | + | This proposal is targeted to php-7 |
- | ===== Proposed Voting Choices | + | ===== Vote ===== |
- | One vote about the proposal in general | + | State whether this project requires 50%+1 majority |
- | * no | + | |
- | * yes | + | |
- | One vote about which variation to use: | + | <doodle title=" |
- | * fastest variation (about 0.1% faster, but indicating argument count and required argument count necessary) | + | |
- | * simpler variation (without indicating argument count, multiline) | + | |
- | * alternative simpler variation (like simpler variation, but multiline) | + | </ |
- | And one vote about the macro names to use: | + | |
- | * begin macro names with ZP_* (like ZP_LONG, less verbose name, but maybe more readable in one line) | + | |
- | * begin macro names with Z_PARAM_* (like Z_PARAM_LONG, | + | |
- | + | ||
- | State whether this project requires 50%+1 majority (see [[voting]]) | + | |
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
* Original Proposal: https:// | * Original Proposal: https:// | ||
- | * Simpler Variation: https://gist.github.com/ | + | |
- | * Alternative Simpler Variation is just trivial changes on the Simpler Variation patch | + | The patch is already included into PHP-7 and wrapped with ifdef/ifndef FAST_ZPP. |
rfc/fast_zpp.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1