Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41291 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56804 invoked from network); 20 Oct 2008 20:09:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Oct 2008 20:09:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=shire@tekrat.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=shire@tekrat.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain tekrat.com from 69.63.177.213 cause and error) X-PHP-List-Original-Sender: shire@tekrat.com X-Host-Fingerprint: 69.63.177.213 sizzo.org Linux 2.6 Received: from [69.63.177.213] ([69.63.177.213:57170] helo=sizzo.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AD/0D-21706-B85ECF84 for ; Mon, 20 Oct 2008 16:09:48 -0400 Received: from [172.24.57.140] (outbound500a.pasd.tfbnw.net [204.15.21.171]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by sizzo.org (Postfix) with ESMTPSA id 1AD2F4F90CF; Mon, 20 Oct 2008 13:09:45 -0700 (PDT) Cc: internals@lists.php.net Message-ID: <243C7392-C6A0-4EE8-8AAA-34964E78D453@tekrat.com> To: Karoly Negyesi In-Reply-To: <7e270cea0810191211w2cb77075y5e0ad78c2f7306f7@mail.gmail.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v926) Date: Mon, 20 Oct 2008 13:09:34 -0700 References: <7e270cea0810191211w2cb77075y5e0ad78c2f7306f7@mail.gmail.com> X-Mailer: Apple Mail (2.926) Subject: Re: [PHP-DEV] An optimization idea From: shire@tekrat.com (shire) On Oct 19, 2008, at 12:11 PM, Karoly Negyesi wrote: > Hi, > > I think zend_hash_compare could get a healthy speed boost in some > cases if first it would check whether the two variables passed to it > are actually the same (because of "reference counting"). Sorry, my C > skills are way too rusty to write the patch which is likely to be just > a few lines long. > A quick patch/test seems to agree with you, I'd be interested to know if you/others are able to apply this patch and see any real-world savings with your web application. The following was done with a debug build of PHP so results are likely exaggerated. I'm also using non-recursive array with 256 byte strings below, results with numeric values are less significant of course (approx a 25% gain)... I'll also look into applying this to some other functions like compare_function where it's likely to yield a larger savings in a general application. patch against php-5.2 CVS head -------------------------- iff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index a1d7071..d11785f 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -1327,16 +1327,14 @@ ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t co IS_CONSISTENT(ht1); IS_CONSISTENT(ht2); - HASH_PROTECT_RECURSION(ht1); - HASH_PROTECT_RECURSION(ht2); - result = ht1->nNumOfElements - ht2->nNumOfElements; - if (result!=0) { - HASH_UNPROTECT_RECURSION(ht1); - HASH_UNPROTECT_RECURSION(ht2); + if (ht1 == ht2 || result!=0) { return result; } + HASH_PROTECT_RECURSION(ht1); + HASH_PROTECT_RECURSION(ht2); + p1 = ht1->pListHead; if (ordered) { p2 = ht2->pListHead; simple test script -------------------------------