Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80863 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87315 invoked from network); 20 Jan 2015 09:06:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2015 09:06:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=ben.coutu@zeyos.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ben.coutu@zeyos.com; 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:51492] helo=mx.zeyon.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4A/F0-15586-29A1EB45 for ; Tue, 20 Jan 2015 04:06:27 -0500 Received: from localhost (mx.zeyon.net [127.0.0.1]) by mx.zeyon.net (Postfix) with ESMTP id 19AB15F8D3 for ; Tue, 20 Jan 2015 10:06:23 +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 eGsj+wv3xeoQ for ; Tue, 20 Jan 2015 10:06:22 +0100 (CET) Received: from cloud.zeyos.com (unknown [109.70.220.163]) by mx.zeyon.net (Postfix) with ESMTPA id 453FF5F85C; Tue, 20 Jan 2015 10:06:20 +0100 (CET) Date: Tue, 20 Jan 2015 10:06:20 +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: <20150120090623.19AB15F8D3@mx.zeyon.net> Subject: Re: [PHP-DEV] Re: Improvements to array.c code base From: ben.coutu@zeyos.com (Benjamin Coutu) Hi,=0A=0ARegarding ARRAY_SLICE(..., preserve_keys=3Dfalse) my whole point w= as that the check for non-numeric key inputs is not necessary if preserve_k= eys is false.=0AIt should basically be analogue to array_values(), but of c= ourse respecting the offset and length boundaries.=0A=0AOne question regard= ing FAST_ZPP: Why is it not used more often, especially in the satndard lib= raries? Is there some particular drawback? I'd like to understand.=0A=0ATha= nks,=0A=0ABen=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 Cou= tu =0ADate: Tue, 20 Jan 2015 09:53:38 +0100=0ASubject:= [PHP-DEV] Re: Improvements to array.c code base=0A=0A=0A=0AHey:=0A=0A=0AOn= 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/array.= 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> a= rray_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> Re= moving the check for packed inputs on line 2376 would improve performance i= f used on non-packed inputs with the default preserve_keys=3Dfalse.=0AThis = is check for non-numeric key inputs=0A=0A> Furthermore, ZEND_HASH_FOREACH_V= AL should be used instead of ZEND_HASH_FOREACH_NUM_KEY_VAL on line 2379.=0A= yeah, I will fix it.=0A> It also think range() should use FAST_ZPP as it is= a basic language feature (other languages even have extra operators for it= , e.g. [0..10])=0A>=0A> =3D=3D=3D RANGE(...) =3D=3D=3D=0A>=0A> range() alwa= ys returns a numerically indexed array [0..count-1]. The resulting array th= erefore should be constructed as a packed array (ZEND_HASH_FILL_PACKED+ZEND= _HASH_FILL_ADD instead of zend_hash_next_index_insert_new).=0A>=0A> =3D=3D= =3D ARRAY_FILL(start_key=3D0, ...)=0A> =3D=3D=3D=0A>=0A> Just like with ra= nge(), array_fill() always returns a numerically indexed array [0..count-1]= if start_key is 0. In this special but very common case the resulting arra= y can be constructed as a packed array (ZEND_HASH_FILL_PACKED+ZEND_HASH_FIL= L_ADD instead of zend_hash_next_index_insert_new).=0A> Another common case = is for start_key to be 1. One could refine the proposed packed-array branch= to just set the first bucket to undefined in this case.=0A>=0A> =3D=3D=3D = COUNT(...) =3D=3D=3D=0A>=0A> count() is so ubiquitous! Giving it an opcode = and making it part of the VM seams reasonable.=0A>=0A> Please let me know y= our thoughts.=0Ahmm, we currently do optimization based on profile against = some real=0Alife apps, like wordpress.=0A=0Arange and array_fill etc doesn'= t used very common.. so I didn't look into it..=0A=0Athanks for the advise,= I will take a look .=0A=0Athanks=0A>=0A> Cheers,=0A>=0A> Ben=0A>=0A> --=0A= >=0A> Benjamin Coutu=0A> Zeyon Technologies Inc.=0A> http://www.zeyos.com= =0A>