Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80861 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82666 invoked from network); 20 Jan 2015 08:30:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2015 08:30:46 -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:51153] helo=mx.zeyon.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/20-15586-4321EB45 for ; Tue, 20 Jan 2015 03:30:45 -0500 Received: from localhost (mx.zeyon.net [127.0.0.1]) by mx.zeyon.net (Postfix) with ESMTP id CB33F5F8F4 for ; Tue, 20 Jan 2015 09:30:40 +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 EwNr9XQxxi4R for ; Tue, 20 Jan 2015 09:30:40 +0100 (CET) Received: from cloud.zeyos.com (unknown [109.70.220.163]) by mx.zeyon.net (Postfix) with ESMTPA id 262C15F8EE; Tue, 20 Jan 2015 09:30:38 +0100 (CET) Date: Tue, 20 Jan 2015 09:30:38 +0100 To: Dmitry Stogov Cc: PHP Internals , Xinchen Hui MIME-Version: 1.0 X-Mailer: ZeyOS Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Message-ID: <20150120083040.CB33F5F8F4@mx.zeyon.net> Subject: Improvements to array.c code base From: ben.coutu@zeyos.com (Benjamin Coutu) Hi Dmitry,=0A=0AI was doing some code review of ext/standard/array.c and ha= ve recognized some potential for a few performance improvements:=0A=0A=3D= =3D=3D ARRAY_SLICE(..., preserve_keys=3Dfalse) =3D=3D=3D=0A=0Aarray_slice()= can always construct a packed array if preserve_keys is false, restricting= it to inputs with packed flag does not make much sense.=0ARemoving the che= ck for packed inputs on line 2376 would improve performance if used on non-= packed inputs with the default preserve_keys=3Dfalse.=0AFurthermore, ZEND_H= ASH_FOREACH_VAL should be used instead of ZEND_HASH_FOREACH_NUM_KEY_VAL on = line 2379.=0AIt also think range() should use FAST_ZPP as it is a basic lan= guage feature (other languages even have extra operators for it, e.g. [0..1= 0])=0A=0A=3D=3D=3D RANGE(...) =3D=3D=3D=0A=0Arange() always returns a numer= ically indexed array [0..count-1]. The resulting array therefore should be = constructed as a packed array (ZEND_HASH_FILL_PACKED+ZEND_HASH_FILL_ADD ins= tead of zend_hash_next_index_insert_new).=0A=0A=3D=3D=3D ARRAY_FILL(start_k= ey=3D0, ...)=0D =3D=3D=3D=0A=0AJust like with range(), 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 array can be constructed as a p= acked array (ZEND_HASH_FILL_PACKED+ZEND_HASH_FILL_ADD instead of zend_hash_= next_index_insert_new).=0AAnother 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=0Acount(= ) is so ubiquitous! Giving it an opcode and making it part of the VM seams = reasonable.=0A=0APlease let me know your thoughts.=0A=0ACheers,=0A=0ABen=0A= =0A-- =0A=0ABenjamin Coutu=0AZeyon Technologies Inc.=0Ahttp://www.zeyos.com