Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81276 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74111 invoked from network); 28 Jan 2015 03:27:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jan 2015 03:27:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.44 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.215.44 mail-la0-f44.google.com Received: from [209.85.215.44] ([209.85.215.44:54374] helo=mail-la0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/84-45774-F2758C45 for ; Tue, 27 Jan 2015 22:27:43 -0500 Received: by mail-la0-f44.google.com with SMTP id s18so16840202lam.3 for ; Tue, 27 Jan 2015 19:27:40 -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=gIROioSbUqOcSQbUUJgwkVl3rom8ed2hxl4CMuFTllI=; b=LyDDTY7PQjsyxpSviSgVgCzItclA/077frrE0Q/RqDPaDAONXAFKNNLhwGNurbx2Pa bZOj1nEdi88A6ZlJg80XtXSJP/HjobC/h0UBGig8tLCVhYlyh86dM9WbzgHp+zAuNE6A YeHBie/7s+0Pe5FZUL8SsFtjZmpDXa70jIHhfwOuTWoTEGHHhJIhgR5IEE/faDQpOtnp MeD1bGLrnFqB4wl7hJQh8IAkiOy4l2c91WYuEhTq56W7nCUnDO/3Ob7/5JZoITO+uvxd u6V21Y+D5BOZ3P3TcaXz29Nss4SdJPh61v9ht6KaBNlA2Cs5oBPTIBp7uV/VZnhGwEC/ IARQ== X-Received: by 10.112.132.2 with SMTP id oq2mr5382092lbb.11.1422415659964; Tue, 27 Jan 2015 19:27:39 -0800 (PST) MIME-Version: 1.0 Sender: laruence@gmail.com Received: by 10.114.64.176 with HTTP; Tue, 27 Jan 2015 19:27:19 -0800 (PST) In-Reply-To: References: <20150122103807.DD8255F8EE@mx.zeyon.net> Date: Wed, 28 Jan 2015 11:27:19 +0800 X-Google-Sender-Auth: unTWOtx_HEyjj-CwhpGAhiZm1gA Message-ID: To: Dmitry Stogov Cc: Benjamin Coutu , Nikita Popov , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Improvements to for-each implementation From: xinchen.h@zend.com (Xinchen Hui) Hey: On Wed, Jan 28, 2015 at 11:22 AM, Xinchen Hui wrote: > Hey: > > On Wed, Jan 28, 2015 at 12:55 AM, Dmitry Stogov wrote: >> Hi, >> >> I'm working on a PoC, implementing the proposed behavior - >> https://gist.github.com/dstogov/a311e8b0b2cabee4dab4 >> >> Only few PHPT tests had to be changed to confirm new behavior and actually >> they started to behave as HHVM. >> 2 tests are still unfixed XFAILed. Foreach by reference is still need to be >> improved to support different array modifications. >> >> The patch makes ~1% improvement on Wordpress-3.6 (saving duplication and >> destruction of 200 arrays on each request) > > I just have got an idea: > > Droping use of ZEND_OP_DATA make it possible to generate better > foreach loop opcodes > > previously FE_RESET and FE_FETCH share one same OP_DATA based on offset. > > 0 FE_RESET > 1 FE_FETCH fail-> 5 > 2 OP_DATA > 3 ..... statements > 4 JMP 1 > 5.... > > without depending on that OP_DATA, we can change this to > > 0 FE_RESET > 1 JMP 3 > 2 ....statements > 3 FE_FETCH success->2 > 4 .... > > that will reduce on JMP in every foreach loop > > could you please also try this? I mean, dropping both ZEND_FE_RESET and FE_FETCH share one ZEND_OP_DATA. the previously example should be: > 0 FE_RESET > 1 JMP 3 > 2 ....statements > 3 FE_FETCH success->2 4 ZEND_OP_DATA > 5 .... thanks > > thanks > >> >> Thanks. Dmitry. >> >> >> >> On Thu, Jan 22, 2015 at 1:38 PM, Benjamin Coutu wrote: >>> >>> Hi Nikita, >>> >>> I would suggest using the proposal for the by-value case and sticking with >>> the current behavior for the by-reference case as you suggested. Granted, we >>> then cannot remove the internal pointer all together, but we would just use >>> it for the less common by-reference case as well as for the legacy >>> reset/next functions, of course. This would still improve most for-each >>> traversals. At least we then wouldn't have to find a replacement solution >>> for rest/prev/next/end. Moreover we can then move the internal position >>> pointer out of the hashtable structure into zend_array because it is only >>> used for userland arrays, not other hash tables (such as object properties >>> or internal structures that build upon the hashtable struct). >>> >>> Thanks, >>> >>> Ben >>> >>> ========== Original ========== >>> From: Nikita Popov >>> To: Benjamin Coutu >>> Date: Thu, 22 Jan 2015 10:53:19 +0100 >>> Subject: Re: [PHP-DEV] Improvements to for-each implementation >>> >>> Doing this was the idea I had in mind as well, i.e. change the semantics >>> of >>> foreach to say that it will always work on a copy for by-value iteration >>> (which ironically avoids having to actually copy it). Note that this will >>> differ from the current behavior in a number of ways. In particular it >>> means that changes to arrays that were references prior to iteration will >>> not influence the iteration. >>> >>> The real question is what we should do in the by-reference case. Given >>> that >>> we need to acquire references to elements of the original array we can't >>> reasonably work with copy-semantics (at least I don't see how). So would >>> we >>> just stick with the previous behavior (using the hash position hack) for >>> that? >>> >>> Nikita >>> >>> >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> > > > > -- > Xinchen Hui > @Laruence > http://www.laruence.com/ -- Xinchen Hui @Laruence http://www.laruence.com/