Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37216 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77658 invoked from network); 25 Apr 2008 14:24:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Apr 2008 14:24:48 -0000 Authentication-Results: pb1.pair.com header.from=php@hristov.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php@hristov.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain hristov.com from 85.92.73.163 cause and error) X-PHP-List-Original-Sender: php@hristov.com X-Host-Fingerprint: 85.92.73.163 iko.gotobg.net Linux 2.5 (sometimes 2.4) (4) Received: from [85.92.73.163] ([85.92.73.163:38561] helo=iko.gotobg.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 35/BA-18287-FA9E1184 for ; Fri, 25 Apr 2008 10:24:47 -0400 Received: from hsi-kbw-091-089-047-238.hsi2.kabelbw.de ([91.89.47.238] helo=[192.168.1.127]) by iko.gotobg.net with esmtpa (Exim 4.68) (envelope-from ) id 1JpOqv-0004qc-EI; Fri, 25 Apr 2008 17:24:43 +0300 Message-ID: <4811E99B.6020004@hristov.com> Date: Fri, 25 Apr 2008 16:24:27 +0200 User-Agent: Thunderbird 2.0.0.12 (X11/20080226) MIME-Version: 1.0 To: Matt Wilmas CC: internals@lists.php.net References: <014b01c8a6db$57d53ba0$0201a8c0@pc1> In-Reply-To: <014b01c8a6db$57d53ba0$0201a8c0@pc1> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - iko.gotobg.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - hristov.com X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] [PATCH] More array filling optimizations From: php@hristov.com (Andrey Hristov) Hi, Matt Wilmas wrote: > Hi all, > > Expanding on the idea of passing a size other than 0 to zend_hash_init(), > when possible, which was done awhile ago in a few areas (to save > resize/rehash operations), I finally added an "array_init_size()" that can > be used instead of array_init(), likewise, when a size is known. As an > example to start, I updated these functions: > > array_*: change_key_case, chunk, combine, fill, fill_keys, flip, keys > (without $search_value), map, rand, reverse, slice, splice, unique (since it > copies all entries first), values; and also compact; func_get_args; > get_defined_vars; str_split; and a couple internal uses. heh, this optimisitations was one of the pluses mysqlnd had over mysqli/libmysql. I am using the following macro: #if PHP_MAJOR_VERSION < 6 #define mysqlnd_array_init(arg, field_count) \ { \ ALLOC_HASHTABLE_REL(Z_ARRVAL_P(arg));\ zend_hash_init(Z_ARRVAL_P(arg), (field_count), NULL, ZVAL_PTR_DTOR, 0); \ Z_TYPE_P(arg) = IS_ARRAY;\ } #else #define mysqlnd_array_init(arg, field_count) \ { \ ALLOC_HASHTABLE_REL(Z_ARRVAL_P(arg));\ zend_u_hash_init(Z_ARRVAL_P(arg), (field_count), NULL, ZVAL_PTR_DTOR, 0, 0);\ Z_TYPE_P(arg) = IS_ARRAY;\ } #endif > Those were the simplest, most obvious cases I found. :-) I didn't test > every function, but for example, the array functions that don't do much work > I found to be ~10% faster (with more than 8 elements, otherwise no resizing > would be needed). If these changes are applied, more can be done where > possible, by others, or I can and send further patches, or update them > myself if I have CVS access... > > http://realplain.com/php/array_init_size.diff > http://realplain.com/php/array_init_size_5_3.diff > > I was playing with initializing scripts' array( ... ) constructs with the > correct size too, but wasn't sure about the changes or what the opinion > would be. Runtime creation is improved with >8 elements, though it adds a > bit of compile overhead. Anyway, separate patches for that: > > http://realplain.com/php/array_init_size_vm.diff > http://realplain.com/php/array_init_size_vm_5_3.diff > > > Thanks, > Matt > >