Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80621 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49878 invoked from network); 16 Jan 2015 07:57:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jan 2015 07:57:07 -0000 Authentication-Results: pb1.pair.com header.from=ben.coutu@zeyos.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ben.coutu@zeyos.com; spf=pass; 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:34291] helo=mx.zeyon.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 21/F1-39838-F44C8B45 for ; Fri, 16 Jan 2015 02:57:06 -0500 Received: from localhost (mx.zeyon.net [127.0.0.1]) by mx.zeyon.net (Postfix) with ESMTP id D39C25F7F7 for ; Fri, 16 Jan 2015 08:57:00 +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 f8GE9Pthw-WD for ; Fri, 16 Jan 2015 08:57:00 +0100 (CET) Received: from cloud.zeyos.com (unknown [109.70.220.163]) by mx.zeyon.net (Postfix) with ESMTPA id 51C0F5F7A9; Fri, 16 Jan 2015 08:56:59 +0100 (CET) Date: Fri, 16 Jan 2015 08:56:59 +0100 To: PHP Internals MIME-Version: 1.0 X-Mailer: ZeyOS Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Message-ID: <20150116075700.D39C25F7F7@mx.zeyon.net> Subject: [PHP-DEV] Generating more efficient code for while-loop From: ben.coutu@zeyos.com (Benjamin Coutu) Hello,=0A=0APlease consider the following PHP code: while ( ) { =0A} It currently compiles to something like this for the Zend Engine: 0: =0A1: JMPZ -> 4 2: =0A3: JMP -> 0 4: ...=0A This can easily be rewritten in an equivalent but much more efficient form: 0: JMP -> 2 1: 2: 3: JMPNZ -> 1 The trick is to jump to the conditional expression before the first iterati= on and then only having to continue with just on conditional jump on every = subsequent cycle.=0A=0AThis would result in only 1 jump per loop iteration = compared to effectively 2 jumps needed per iteration with the current imple= mentation. =0AIt would also make the loop tighter as upon entering the loop (after fir= st conditional evaluation), one less opcode remains relevant to the loop.= =0A=0AAn analogous approach can be taken for the for-loop.=0A=0AThanks,=0A= =0ABen=0A=0APS: This is my first post on a PHP mailinglist - I am very exci= ted! :)=0A=0A-- =0A=0ABenjamin Coutu=0AZeyon Technologies Inc.=0Ahttp://www= .zeyos.com