Hi Oleg, this is already accomplished.
if (! <exp>) <stat> would usually be compiled to: 1: <exp> 2: NOT 3: JMPZ -> 5 4: <stat> 5: ... But OpCache's built-in optimizer (https://github.com/php/php-src/blob/master/ext/opcache/Optimizer/block_pass.c) is able to recognize this during the block level analysis and creates the following opcodes for the Zend engine: 1: <exp> 2: JMPNZ -> 4 3: <stat> 4: ... Please note that NOT+JMPZ are converted to an equivalent single opcode JMPNZ. An extra NOT_EMPTY opcode is therefore not necessary. I do not quite understand why you experience a performance difference, probably OpCache is not enabled or optimization flags are not properly set. Please see http://php.net/manual/en/book.opcache.php for more info. Cheers, Benjamin Coutu ========== Original ========== From: Oleg Serov <sero...@gmail.com> To: internals@lists.php.net Date: Sun, 08 Feb 2015 00:13:05 +0100 Subject: [PHP-DEV] Idea of optimizing php !empty(...) expression. I use !empty() very often and decided to make a benchmark test. Here is the code and results: http://pastebin.com/fMhhdQiW if (!empty(...)) working on 23% slower than if (empty()) expression. So if create new operator not_empty() it will improve performance. The first question is: What do you think about optimizing !empty(...), do we need it ? And I see two way to make this happen. 1. Create new language entity "not_empty". 2. Improve parser and help to handle "!empty" calls different way. It is obviously that option 2 is better. Is it real to optimize parser that way? Thanks! -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php