Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82104 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62259 invoked from network); 7 Feb 2015 23:54:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Feb 2015 23:54:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=ben.coutu@zeyos.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ben.coutu@zeyos.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zeyos.com designates 109.70.220.166 as permitted sender) X-PHP-List-Original-Sender: ben.coutu@zeyos.com X-Host-Fingerprint: 109.70.220.166 unknown Received: from [109.70.220.166] ([109.70.220.166:45195] helo=mx.zeyon.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3E/81-50836-2B5A6D45 for ; Sat, 07 Feb 2015 18:54:26 -0500 Received: from localhost (mx.zeyon.net [127.0.0.1]) by mx.zeyon.net (Postfix) with ESMTP id 930125F810 for ; Sun, 8 Feb 2015 00:54:22 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mx.zeyon.net Received: from mx.zeyon.net ([127.0.0.1]) by localhost (mx.zeyon.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wNJYZPFoiXTf for ; Sun, 8 Feb 2015 00:54:21 +0100 (CET) Received: from cloud.zeyos.com (unknown [109.70.220.163]) by mx.zeyon.net (Postfix) with ESMTPA id E17C25F724; Sun, 8 Feb 2015 00:54:20 +0100 (CET) Date: Sun, 08 Feb 2015 00:54:20 +0100 To: Oleg Serov , internals@lists.php.net MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Message-ID: <20150207235422.930125F810@mx.zeyon.net> Subject: Re: [PHP-DEV] Idea of optimizing php !empty(...) expression. From: ben.coutu@zeyos.com (Benjamin Coutu) Hi Oleg, this is already accomplished.=20 if (! ) would usually be compiled to: 1: 2: NOT 3: JMPZ -> 5 4: 5: ... But OpCache's built-in optimizer (https://github.com/php/php-src/blob/maste= r/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: 2: JMPNZ -> 4 3: 4: ... Please note that NOT+JMPZ are converted to an equivalent single opcode JMPN= Z. An extra NOT_EMPTY opcode is therefore not necessary. I do not quite understand why you experience a performance difference, prob= ably OpCache is not enabled or optimization flags are not properly set. Ple= ase see http://php.net/manual/en/book.opcache.php for more info. Cheers, Benjamin Coutu =0A=0A=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Original =3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=0AFrom: Oleg Serov =0ATo: internals@lists.php.net=0A= Date: Sun, 08 Feb 2015 00:13:05 +0100=0ASubject: [PHP-DEV] Idea of optimizi= ng php !empty(...) expression.=0A=0AI use !empty() very often and decided t= o make a benchmark test.=0A=0AHere is the code and results: http://pastebin= .com/fMhhdQiW=0A=0Aif (!empty(...)) working on 23% slower than if (empty())= expression.=0A=0ASo if create new operator not_empty() it will improve per= formance.=0A=0AThe first question is: What do you think about optimizing !e= mpty(...), do=0Awe need it ?=0A=0AAnd I see two way to make this happen.=0A= =0A1. Create new language entity "not_empty".=0A2. Improve parser and help = to handle "!empty" calls different way.=0A=0AIt is obviously that option 2 = is better. Is it real to optimize parser that=0Away?=0A=0AThanks!