Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81249 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11361 invoked from network); 27 Jan 2015 16:55:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jan 2015 16:55:50 -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.173 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.173 mail-vc0-f173.google.com Received: from [209.85.220.173] ([209.85.220.173:41819] helo=mail-vc0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8A/19-59067-313C7C45 for ; Tue, 27 Jan 2015 11:55:47 -0500 Received: by mail-vc0-f173.google.com with SMTP id id10so5056875vcb.4 for ; Tue, 27 Jan 2015 08:55:44 -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=NpSgAk+xyVe8HBfbg2IsgLuzWPZ6pqtVOE8rptype7U=; b=mWQ4TLzJ4s+RW7IC8hhzyIclxYwwEwGkNnZJ/IieSQE1NVGn9sGl7l7DW2WKDBK7kp Q1QOjI2i4FBabBjZMnKD/sgBrLBasItldTE1PKLrVi1wwDVdL4xz5rqvaymrAhctSlYt uvNvaxXV8t1roroE6eg+Ffq8Hk23FIrBC4cGdujADAqki/DQWYUBpAYsA9191I3Glhtk vuSmp2WmWVLAjC7E3aYneCS725SX+gyuND9sfqb68iVaFk3Is40TANAgdyKpbxWccUJL wkqW7Q0Wtcc97/w+1O4uPK5Rjkk4MX+X2ncIjrnJiLjQAzZ08rDPIfQ4Yx6c8rl199Bt 99ug== X-Gm-Message-State: ALoCoQmJcdni0whl4cIvedV+hUp+2YizMX2hkvBpg61iHwAjBSSFjGXgUG51/0hYpHCRMSVfMI0WVosdqaecbpXq0Ge14y2oH61CYn/+wFLiklsPKVv10Go5d368dxunwfGF+HUyXsNtaemgsX7Fd3+QugvL9cNEIQ== MIME-Version: 1.0 X-Received: by 10.221.21.131 with SMTP id qs3mr1066200vcb.33.1422377744607; Tue, 27 Jan 2015 08:55:44 -0800 (PST) Received: by 10.52.26.40 with HTTP; Tue, 27 Jan 2015 08:55:44 -0800 (PST) In-Reply-To: <20150122103807.DD8255F8EE@mx.zeyon.net> References: <20150122103807.DD8255F8EE@mx.zeyon.net> Date: Tue, 27 Jan 2015 20:55:44 +0400 Message-ID: To: Benjamin Coutu Cc: Nikita Popov , Xinchen Hui , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11339f8a344726050da52073 Subject: Re: [PHP-DEV] Improvements to for-each implementation From: dmitry@zend.com (Dmitry Stogov) --001a11339f8a344726050da52073 Content-Type: text/plain; charset=UTF-8 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) 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 > > --001a11339f8a344726050da52073--