rfc:error-optimizations
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:error-optimizations [2010/08/21 17:32] – kalle | rfc:error-optimizations [2010/08/24 03:26] – kalle | ||
---|---|---|---|
Line 11: | Line 11: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | ... | + | Every error in PHP is formatting in a sprintf()-alike syntax using one of our many error handling functions, every time an error, warning or notice occurs, we hit the error handlers, format them even if we never wish to display the errors. This RFC proposes a way that could be used to reduce that. |
===== Implementation ===== | ===== Implementation ===== | ||
- | ... | + | This RFC's implementation, |
+ | <code c> | ||
+ | | ||
+ | zend_bool error_stack_enabled: | ||
+ | zend_bool error_stack_logging: | ||
+ | zend_error_arguments error_stack[]; | ||
+ | int error_stack_size: | ||
+ | ... | ||
+ | </ | ||
- | ==== log_errors ==== | + | The new structure, " |
- | ... | + | <code c> |
+ | struct { | ||
+ | /* Message format */ | ||
+ | const char *format; | ||
+ | |||
+ | /* Error type */ | ||
+ | const short type; | ||
+ | |||
+ | /* File, and line number, if any */ | ||
+ | const char *filename; | ||
+ | const int lineno; | ||
+ | |||
+ | /* Arguments */ | ||
+ | va_args arguments; | ||
+ | } _zend_error_arguments; | ||
+ | |||
+ | typedef struct _zend_error_arguments zend_error_arguments; | ||
+ | </ | ||
+ | |||
+ | The error_stack_logging executor global needs to match that of INI_BOOL(" | ||
+ | |||
+ | <code c> | ||
+ | zend_error_arguments arguments; | ||
+ | |||
+ | /* put the data into the arguments structure */ | ||
+ | |||
+ | if (EG(error_stack_enabled) && EG(error_stack_logging)) { | ||
+ | EG(error_stack)[EG(error_stack_size)] = arguments; | ||
+ | |||
+ | if (EG(error_stack_logging)) { | ||
+ | /* dispatch to error logging hook */ | ||
+ | } else { | ||
+ | /* no logging, increase the stack size */ | ||
+ | |||
+ | ++EG(error_stack_size); | ||
+ | } | ||
+ | } else { | ||
+ | /* BC code */ | ||
+ | } | ||
+ | </ | ||
==== error_get_last() ==== | ==== error_get_last() ==== | ||
- | .... | + | error_get_last() should internally check if EG(error_stack_enabled) is on, like: |
+ | |||
+ | <code c> | ||
+ | if (EG(error_stack_enabled) && EG(error_stack_size)) { | ||
+ | char *error; | ||
+ | |||
+ | /* dispatch to formatting function, and copy it into, the " | ||
+ | |||
+ | RETURN_STRING(error, | ||
+ | } else { | ||
+ | /* BC code */ | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== $php_errormsg ==== | ||
+ | |||
+ | This one is a tricky one, as we do not have any hooks for altering variables at reading, nor do we have JIT assignments. I think the best solution here is to simply remove $php_errormsg and require userland to use error_get_last() if they *REALLY* want the last errors, without depending on the track_errors ini options to be on. | ||
+ | |||
+ | If its not removed, then we cannot gain any optimization with track_errors = On at all, so if thats the case, it has to be taken into account when initializing the error_stack executor globals. | ||
==== Memory usage ==== | ==== Memory usage ==== | ||
- | ... | + | Obvious the memory usage here can grow quite rapidly, but people who would use this feature already takes great care of their code to not assume the opposite. |
+ | |||
+ | ===== Additional notes ===== | ||
+ | |||
+ | * While altering the internal logic of zend_error() to match that of the above, it might be worth passing the TSRMLS macros to it, to save some TS performance at every call, which itself is a bonus for multithreaded SAPIs. |
rfc/error-optimizations.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1