Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80865 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90754 invoked from network); 20 Jan 2015 09:21:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2015 09:21:51 -0000 Authentication-Results: pb1.pair.com header.from=ben.coutu@zeyos.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ben.coutu@zeyos.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zeyos.com designates 109.70.220.166 as permitted sender) X-PHP-List-Original-Sender: ben.coutu@zeyos.com X-Host-Fingerprint: 109.70.220.166 unknown Received: from [109.70.220.166] ([109.70.220.166:51652] helo=mx.zeyon.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2C/A1-15586-D2E1EB45 for ; Tue, 20 Jan 2015 04:21:50 -0500 Received: from localhost (mx.zeyon.net [127.0.0.1]) by mx.zeyon.net (Postfix) with ESMTP id E93615F8D3 for ; Tue, 20 Jan 2015 10:21:46 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mx.zeyon.net Received: from mx.zeyon.net ([127.0.0.1]) by localhost (mx.zeyon.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MnxgTncrsY2p for ; Tue, 20 Jan 2015 10:21:45 +0100 (CET) Received: from cloud.zeyos.com (unknown [109.70.220.163]) by mx.zeyon.net (Postfix) with ESMTPA id 8C0EE5F85C; Tue, 20 Jan 2015 10:21:43 +0100 (CET) Date: Tue, 20 Jan 2015 10:21:43 +0100 To: Xinchen Hui Cc: Dmitry Stogov , PHP Internals MIME-Version: 1.0 X-Mailer: ZeyOS Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Message-ID: <20150120092146.E93615F8D3@mx.zeyon.net> Subject: Re: [PHP-DEV] Re: Improvements to array.c code base From: ben.coutu@zeyos.com (Benjamin Coutu) Sorry, your right of course as not preserving keys only applies to numeric = indices.=0A=0A=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Original =3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=0AFrom: Xinchen Hui =0ATo: Benjamin Coutu =0ADate: Tue, 20 Jan 2015 10:13:04 +0100=0ASubject: Re: [= PHP-DEV] Re: Improvements to array.c code base=0A=0A=0A=0AHey:=0A=0AOn Tue,= Jan 20, 2015 at 5:06 PM, Benjamin Coutu wrote:=0A> H= i,=0A>=0A> Regarding ARRAY_SLICE(..., preserve_keys=3Dfalse) my whole point= was that the check for non-numeric key inputs is not necessary if preserve= _keys is false.=0A> It should basically be analogue to array_values(), but = of course respecting the offset and length boundaries.=0AI am not sure I un= derstood your point.=0A=0Aeven if preserve_keys is false, it still use stri= ng key if origin is string key.=0A=0A=0A>=0A> One question regarding FAST_Z= PP: Why is it not used more often, especially in the satndard libraries? Is= there some particular drawback? I'd like to understand.=0A=0Ahmm, https://= wiki.php.net/rfc/fast_zpp :)=0A=0Athanks=0A>=0A> Thanks,=0A>=0A> Ben=0A>=0A= > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Original =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= > From: Xinchen Hui =0A> To: Benjamin Coutu =0A> Date: Tue, 20 Jan 2015 09:53:38 +0100=0A> Subject: [PHP-DEV]= Re: Improvements to array.c code base=0A>=0A>=0A>=0A> Hey:=0A>=0A>=0A> On = Tue, Jan 20, 2015 at 4:30 PM, Benjamin Coutu wrote:= =0A>> Hi Dmitry,=0A>>=0A>> I was doing some code review of ext/standard/arr= ay.c and have recognized some potential for a few performance improvements:= =0A>>=0A>> =3D=3D=3D ARRAY_SLICE(..., preserve_keys=3Dfalse) =3D=3D=3D=0A>>= =0A>> array_slice() can always construct a packed array if preserve_keys is= false, restricting it to inputs with packed flag does not make much sense.= =0A>> Removing the check for packed inputs on line 2376 would improve perfo= rmance if used on non-packed inputs with the default preserve_keys=3Dfalse.= =0A> This is check for non-numeric key inputs=0A>=0A>> Furthermore, ZEND_HA= SH_FOREACH_VAL should be used instead of ZEND_HASH_FOREACH_NUM_KEY_VAL on l= ine 2379.=0A> yeah, I will fix it.=0A>> It also think range() should use FA= ST_ZPP as it is a basic language feature (other languages even have extra o= perators for it, e.g. [0..10])=0A>>=0A>> =3D=3D=3D RANGE(...) =3D=3D=3D=0A>= >=0A>> range() always returns a numerically indexed array [0..count-1]. The= resulting array therefore should be constructed as a packed array (ZEND_HA= SH_FILL_PACKED+ZEND_HASH_FILL_ADD instead of zend_hash_next_index_insert_ne= w).=0A>>=0A>> =3D=3D=3D ARRAY_FILL(start_key=3D0, ...)=0A>> =3D=3D=3D=0A>>= =0A>> Just like with range(), array_fill() always returns a numerically ind= exed array [0..count-1] if start_key is 0. In this special but very common = case the resulting array can be constructed as a packed array (ZEND_HASH_FI= LL_PACKED+ZEND_HASH_FILL_ADD instead of zend_hash_next_index_insert_new).= =0A>> Another common case is for start_key to be 1. One could refine the pr= oposed packed-array branch to just set the first bucket to undefined in thi= s case.=0A>>=0A>> =3D=3D=3D COUNT(...) =3D=3D=3D=0A>>=0A>> count() is so ub= iquitous! Giving it an opcode and making it part of the VM seams reasonable= .=0A>>=0A>> Please let me know your thoughts.=0A> hmm, we currently do opti= mization based on profile against some real=0A> life apps, like wordpress.= =0A>=0A> range and array_fill etc doesn't used very common.. so I didn't lo= ok into it..=0A>=0A> thanks for the advise, I will take a look .=0A>=0A> th= anks=0A>>=0A>> Cheers,=0A>>=0A>> Ben=0A>>=0A>> --=0A>>=0A>> Benjamin Coutu= =0A>> Zeyon Technologies Inc.=0A>> http://www.zeyos.com=0A>>=0A>