Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81265 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48027 invoked from network); 27 Jan 2015 22:36:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jan 2015 22:36:29 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.171 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.212.171 mail-wi0-f171.google.com Received: from [209.85.212.171] ([209.85.212.171:49150] helo=mail-wi0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/60-45774-BE218C45 for ; Tue, 27 Jan 2015 17:36:27 -0500 Received: by mail-wi0-f171.google.com with SMTP id l15so8091330wiw.4 for ; Tue, 27 Jan 2015 14:36:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=TosMcwpuRsXN309RypEMeOihZZHEDx3+91LmNFk20gU=; b=qAA5sT+0aTPnWZTHI+rMxwvs1v1Fnx/Sm9AAc+d4H2v3yPYwZg5g0tLH4Sy290fGDb as8+Am/jhxICXvHUM7ZPZlg42IvIOOMzcLahXVFTQPnwY8+PYluVquflYPtPhmjkav1d GF3iNRJFeloUPFWcybKXgL08d6xPXaGOT5nRxaHmc2MyywWd75tdeh2hMpG+6mN1EZfn ns8WLBFTomMM0pySwzl0KSI5R1eEgQAFieQGC4muqrbHVNFmqabsjwu/lYhDHUhMhLtq 9xk4d1aMri7f4uK3/eq3M5VxdD4CNNmz62OtIqLJYZ4634Fs3ohkM7hm+WfdGP45uust pUPA== MIME-Version: 1.0 X-Received: by 10.180.211.2 with SMTP id my2mr676129wic.3.1422398184215; Tue, 27 Jan 2015 14:36:24 -0800 (PST) Received: by 10.27.10.138 with HTTP; Tue, 27 Jan 2015 14:36:24 -0800 (PST) In-Reply-To: References: <20150122103807.DD8255F8EE@mx.zeyon.net> Date: Tue, 27 Jan 2015 23:36:24 +0100 Message-ID: To: Dmitry Stogov Cc: Benjamin Coutu , Xinchen Hui , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c37c187fdc39050da9e285 Subject: Re: [PHP-DEV] Improvements to for-each implementation From: nikita.ppv@gmail.com (Nikita Popov) --001a11c37c187fdc39050da9e285 Content-Type: text/plain; charset=UTF-8 On Tue, Jan 27, 2015 at 5:55 PM, 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) > > Thanks. Dmitry. > I quickly looked over the patch, some notes: * 171: Can directly use GET_OP1_ZVAL_PTR_DEREF * For iterator failures (exception) you use FREE_OP1_IF_VAR(). Is this enough? If the object is a TMP_VAR, don't we have to free it as well? * For objects it will still be possible to modify the hashtable during iteration even in the _R case, correct? I assume we just don't care about this edge case. * 315: In RESET_RW you now always create a reference for VAR|CV operands. However for the get_iterator case we don't need this, right? * 328: In the non VAR|CV case SEPARTE_ARRAY is not used. As we're going to change the IAP, this is probably necessary in this case as well. * For RW iterator failures FREE_OP1_VAR_PTR() is used. This probably leaks in the TMP case. (Same for the "invalid argument" case.) What concerns me a bit is the new FETCH_RW implementation, because it no longer checks the internal pointer against the external one. This effectively means that foreach by reference behavior will be influenced a lot by details of the hashtable implementation. An example: $array = [0, 1, 2, 3, 4, 5, 6, 7]; unset($array[0], $array[1], $array[2], $array[3]); foreach ($array as &$ref) { var_dump($ref); //$array[42] = 42; } Without the commented line this will just print the numbers 4, 5, 6, 7. If you uncomment the line it will only print 4. (Because the append caused a rehash and arData was compacted, so the position now points past all elements). The previous output would have been 4, 5, 6, 7, 42, which is closer to what you would expect. Maybe better to keep the pos != nInternalPointer code? Thanks, Nikita --001a11c37c187fdc39050da9e285--