Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41664 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76820 invoked from network); 4 Nov 2008 21:54:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Nov 2008 21:54:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=mls@pooteeweet.org; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=mls@pooteeweet.org; sender-id=unknown Received-SPF: error (pb1.pair.com: domain pooteeweet.org from 88.198.8.16 cause and error) X-PHP-List-Original-Sender: mls@pooteeweet.org X-Host-Fingerprint: 88.198.8.16 bigtime.backendmedia.com Linux 2.6 Received: from [88.198.8.16] ([88.198.8.16:46364] helo=bigtime.backendmedia.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EF/92-15458-AA4C0194 for ; Tue, 04 Nov 2008 16:54:51 -0500 Received: from localhost (unknown [127.0.0.1]) by bigtime.backendmedia.com (Postfix) with ESMTP id 2A17B414405A; Tue, 4 Nov 2008 21:55:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at backendmedia.com Received: from bigtime.backendmedia.com ([127.0.0.1]) by localhost (bigtime.backendmedia.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j9BRFxKXfbH5; Tue, 4 Nov 2008 22:55:36 +0100 (CET) Received: from [192.168.0.151] (77-58-151-147.dclient.hispeed.ch [77.58.151.147]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: mls@pooteeweet.org) by bigtime.backendmedia.com (Postfix) with ESMTP id 25DBB4144009; Tue, 4 Nov 2008 22:55:32 +0100 (CET) Cc: Karoly Negyesi , internals@lists.php.net Message-ID: To: shire In-Reply-To: <243C7392-C6A0-4EE8-8AAA-34964E78D453@tekrat.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v929.2) Date: Tue, 4 Nov 2008 22:53:36 +0100 References: <7e270cea0810191211w2cb77075y5e0ad78c2f7306f7@mail.gmail.com> <243C7392-C6A0-4EE8-8AAA-34964E78D453@tekrat.com> X-Mailer: Apple Mail (2.929.2) Subject: Re: [PHP-DEV] An optimization idea From: mls@pooteeweet.org (Lukas Kahwe Smith) Hello again, once again top posting this this is fairly old .. however for something that is sounding so promising I am wondering why this hasnt been picked up .. regards, Lukas On 20.10.2008, at 22:09, shire wrote: > > 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 > ------------------------------- > > $arr1 = array(); > for ($i=0; $i < 10000; $i++) { > $arr1[$i] = str_repeat('x', 256); > } > $arr2 = array(); > for ($i=0; $i < 10000; $i++) { > $arr2[$i] = str_repeat('x', 256); > } > $arr3 = $arr1; > > $count = 0; > $start = microtime(true); > for ($i = 0; $i < 1000; $i++) { > if ($arr1 == $arr2) { > $count++; > } > } > $stop = microtime(true); > echo "different array time: ".($stop-$start)."\n"; > echo "count: $count \n"; > > $count = 0; > $start = microtime(true); > for ($i = 0; $i < 1000; $i++) { > if ($arr1 == $arr3) { > $count++; > } > } > $stop = microtime(true); > echo "identical array time: ".($stop-$start)."\n"; > echo "count: $count \n"; > ------------------------------- > > (un-patched php build) > shire@shirebook:~/data/php/git/php$ ./sapi/cli/php.vanilla test.php > different array time: 4.2019698619843 > count: 1000 > identical array time: 2.4957029819489 > count: 1000 > > (patched build) > shire@shirebook:~/data/php/git/php$ ./sapi/cli/php test.php > different array time: 4.059928894043 > count: 1000 > identical array time: 0.00043511390686035 > count: 1000 > > > -shire > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > Lukas Kahwe Smith mls@pooteeweet.org