Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51163 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86855 invoked from network); 31 Dec 2010 17:57:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Dec 2010 17:57:30 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:43188] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A0/00-21194-4791E1D4 for ; Fri, 31 Dec 2010 12:57:16 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 38DF7700044F for ; Fri, 31 Dec 2010 17:56:50 +0000 (WET) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id 3FS4vGKWtUWT for ; Fri, 31 Dec 2010 17:56:49 +0000 (WET) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp2.ist.utl.pt (Postfix) with ESMTP id F33CD7000449 for ; Fri, 31 Dec 2010 17:56:48 +0000 (WET) Received: from damnation.dulce.lo.geleia.net (91.80.136.95.rev.vodafone.pt [95.136.80.91]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id DFE1320010DA for ; Fri, 31 Dec 2010 17:56:48 +0000 (WET) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: Date: Fri, 31 Dec 2010 17:56:48 -0000 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_IST?= Message-ID: In-Reply-To: User-Agent: Opera Mail/11.00 (Win32) Subject: Re: [PHP-DEV] Zend engine's hashtable performance tweaks From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Fri, 31 Dec 2010 14:40:44 -0000, Marcin Babij wrote: > Why we do this? > We run profiling on our production servers and found out that zend_hash_* > functions take 10-20% CPU time of request. So there is some room for easy > improvements. > > What was done? > - Hash function in zend_hash.h was rebuilt and became much faster, > without losing the most important properties. > - Hashtable implementation was changed from Simple chaining to Open > addressing with linear probing, but with linked bucket, not included in > hash array, which causes: > -- Bucket structure to lose 2 pointers. > -- Searching works similar, but don't have to jump with pointers stored > in different memory locations, inserting, deleting and rehashing don't > need > to update linked list, but must search for first empty bucket, which is > fast, because it scans continuous memory. > -- Load factor decreases from 1.0 to 0.5-0.75 to make less collisions and > faster hashtable, which in turn increases memory footprint a little. > - Open addressing doesn't change significantly performance, but next > thing was to create new array (arEmpty), which is of size nTableSize > bytes, > which keeps track of used/empty buckets and makes inserting and rehashing > much faster. In future it can be tested as bit-array with size of > nTableSize/8 bytes. Nice work. Only two comments: This is much faster than just testing the value of the Bucket pointer for NULL (BTW, NULL pointer != 0 bit pattern, but I guess this is a lost cause in PHP's codebase...)? I'm a bit surprised; though perhaps this could allow more cache hits (and indicates changing it into a bit array could very well be beneficial). A patch against trunk would be nicer since that's where there's a chance this will be merged to. Also, since you're changing the hash function, html_table_gen.php must changed and run to regenerate html_tables.h. See http://lxr.php.net/xref/PHP_TRUNK/ext/standard/html_tables/html_table_gen.php#722 (ignore the comment; there's obviously nothing unrolled). -- Gustavo Lopes