Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80652 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30843 invoked from network); 16 Jan 2015 16:58:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jan 2015 16:58:57 -0000 Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.176 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.217.176 mail-lb0-f176.google.com Received: from [209.85.217.176] ([209.85.217.176:40721] helo=mail-lb0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6B/61-23044-F4349B45 for ; Fri, 16 Jan 2015 11:58:55 -0500 Received: by mail-lb0-f176.google.com with SMTP id p9so19504802lbv.7 for ; Fri, 16 Jan 2015 08:58:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=S6nDtZwXZpvv7JdFnrAZRenkI1vqspdS/cH8cHySIdc=; b=VEqtQP8ikCT8p5NotUZLDg2fa0rY7cCXXTgJSkiMjtZdfXjCNtMRpELOq8ZKsiftw1 Atb0otc9bO1chNmI39Lr+s2842GalWP5x8k5ocIEZTNemwlI/VPUV2DdHJ2O8wvOpcOy GUjp9AtqDAPU2vQlbY0KbfbyL/4RV5WXl5/tZmZoU2AC+2EIEbr6NL8k3T5jInFcczgA 4sC4hnIr7yGbrKGS/YfIEpJZN5z0WgQVpK+YuS7a/OPvpemc2ue4o1rA/5cQtGGh4/Pe kuBK5IukQuzqFum5YpR5p+g7zvqlNCsF7w6/YfkzuS/ERY5bhugKqyKZghMjIy88+jst elww== X-Received: by 10.112.14.6 with SMTP id l6mr16841849lbc.91.1421427532089; Fri, 16 Jan 2015 08:58:52 -0800 (PST) MIME-Version: 1.0 Sender: laruence@gmail.com Received: by 10.114.64.176 with HTTP; Fri, 16 Jan 2015 08:58:31 -0800 (PST) In-Reply-To: References: <20150116075700.D39C25F7F7@mx.zeyon.net> Date: Sat, 17 Jan 2015 00:58:31 +0800 X-Google-Sender-Auth: Z9ONp-UEPSp7T1aYvtUMBz_0C4M Message-ID: To: Dmitry Stogov Cc: Benjamin Coutu , PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Generating more efficient code for while-loop From: xinchen.h@zend.com (Xinchen Hui) Hey: On Sat, Jan 17, 2015 at 12:12 AM, Dmitry Stogov wrote: > Hi Benjamin, > > Thanks for idea. > With PHP7 AST compiler, it's quite easy to implement this (it took us 15 > minutes to try :) yeah... by handy :) > However, it doesn't make big improvement on our benchmarks. in reallife app, IR has no significant difference while running wordpress homepage thanks > We will take a look into possibilities to apply your idea to other patterns > (e.g. for and foreach loops). > > Anyway, it makes full sense to include this optimization into PHP7. > I just like to try other opportunities first. > > Thanks. Dmitry. > > On Fri, Jan 16, 2015 at 10:56 AM, Benjamin Coutu > wrote: >> >> Hello, >> >> Please consider the following PHP code: >> >> while ( ) { >> >> } >> >> It currently compiles to something like this for the Zend Engine: >> >> 0: >> 1: JMPZ -> 4 >> 2: >> 3: JMP -> 0 >> 4: ... >> >> 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 >> iteration and then only having to continue with just on conditional jump on >> every subsequent cycle. >> >> This would result in only 1 jump per loop iteration compared to >> effectively 2 jumps needed per iteration with the current implementation. >> >> It would also make the loop tighter as upon entering the loop (after first >> conditional evaluation), one less opcode remains relevant to the loop. >> >> An analogous approach can be taken for the for-loop. >> >> Thanks, >> >> Ben >> >> PS: This is my first post on a PHP mailinglist - I am very excited! :) >> >> -- >> >> Benjamin Coutu >> Zeyon Technologies Inc. >> http://www.zeyos.com >> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> > -- Xinchen Hui @Laruence http://www.laruence.com/