Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80653 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32588 invoked from network); 16 Jan 2015 17:09:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jan 2015 17:09:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.174 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.174 mail-vc0-f174.google.com Received: from [209.85.220.174] ([209.85.220.174:56449] helo=mail-vc0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F3/C1-23044-4D549B45 for ; Fri, 16 Jan 2015 12:09:41 -0500 Received: by mail-vc0-f174.google.com with SMTP id id10so7005758vcb.5 for ; Fri, 16 Jan 2015 09:09:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=EtKobpSweasQSXcQ3VH/mGSpYD1NSNpientzN05tYgk=; b=SPG8OnrkvmOl9/mHnc/lMP5n1z7THWpd8fioUy58ioehdn2Y44vul0CFsdd1vX4kH2 rk6Ag7tLNFAohoG3nI0KygGBEJxd90FkmV8BjzybutWkFNGDDfh32N28K2Qu4U8+aAu9 3gdYaUsi4UjJoMUwuBYPCqu9N9l3L640nbZmCDJw7ILabtVH+ONHApaoX6IqUpt0hxND konmDNuljWMDLoFMan5s/xMTMmOaLw1jxTa1mZBUEqxdD3w241BIjRN/s0SIrUZgH0xk +3wWJKVseg79yPX0qwSS1H+Wcl3tp5CuUtk76DMYenzM5eApie7zkfquKL5UsqWWrGiO Ul9Q== X-Gm-Message-State: ALoCoQmYuI8HLDdA2YZ+VRuhuHvHK4OMRnqAtXGaoMZmkXxO+HzpIhwGbwpZPUvYXJ3FoDw2joLx9nVt7nmtVGTaXHInXRGxROdc69SM4iFJ0fH3Bie33gZCks7ZBQhkgTViiEFHAMLv3nw/z560Wc7ysCxtDyx1/Q== MIME-Version: 1.0 X-Received: by 10.52.10.198 with SMTP id k6mr6730104vdb.38.1421428177747; Fri, 16 Jan 2015 09:09:37 -0800 (PST) Received: by 10.52.26.40 with HTTP; Fri, 16 Jan 2015 09:09:37 -0800 (PST) In-Reply-To: References: <20150116075700.D39C25F7F7@mx.zeyon.net> Date: Fri, 16 Jan 2015 21:09:37 +0400 Message-ID: To: Xinchen Hui , Nikita Popov Cc: Benjamin Coutu , PHP Internals Content-Type: multipart/alternative; boundary=20cf30334e259bda40050cc8099a Subject: Re: [PHP-DEV] Generating more efficient code for while-loop From: dmitry@zend.com (Dmitry Stogov) --20cf30334e259bda40050cc8099a Content-Type: text/plain; charset=UTF-8 See the patch for "while" and "for" loops https://gist.github.com/dstogov/9cc5767a14f3b88e1275 All tests passed. The patch leads to 2% improvement in number of CPU instructions retired on bench.php. Unfortunately, It doesn't make any visible speed difference. Anyway, I'm going to commit it on Monday. Xinchen, Nikita, please verify me. Thanks. Dmitry. On Fri, Jan 16, 2015 at 7:58 PM, Xinchen Hui wrote: > 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/ > --20cf30334e259bda40050cc8099a--