Hi Dmitry, all,
Has it been considered to use __attribute__((cold)) on, for example,
error-type functions? I happened to notice this part about it in the GCC
docs [1] a couple days ago: "The paths leading to calls of cold functions
within code are marked as unlikely by the branch prediction mechanism."
A while ago I figured that, technically, many if () conditions for errors
could use UNEXPECTED(), but that would be overkill for each possible tiny
advantage. But that sort of happens automatically for conditions leading to
"cold" functions! :^)
I was thinking of widely-used functions like php_error_docref*, zend_error
(and related); also noticed exception/throwing functions, or even
zend_accel_error in opcache.
I didn't do any profiling, just simply tried marking *only*
php_error_docref0 cold. With GCC 4.8, it reduced the size by almost 4 KB
(-O2, --disable-all CLI). And checking through the code, it did indeed move
the calls around (e.g. out of fast path) in many cases compared to default
(some cases didn't optimize more).
Looks like more zend_error calls in VM that aren't already part of
UNEXPECTED() conditions could be moved "out of the way" if marked cold...
[1] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
Thoughts?
Thanks,
Matt
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php