Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41737 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27483 invoked from network); 6 Nov 2008 18:37:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Nov 2008 18:37:17 -0000 Authentication-Results: pb1.pair.com header.from=shire@tekrat.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=shire@tekrat.com; spf=permerror; 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:39311] helo=sizzo.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BB/91-44653-D5933194 for ; Thu, 06 Nov 2008 13:37:17 -0500 Received: from shirebook.tekrat.com (dsl092-189-079.sfo1.dsl.speakeasy.net [66.92.189.79]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by sizzo.org (Postfix) with ESMTPSA id C7A6F4F958A; Thu, 6 Nov 2008 10:37:13 -0800 (PST) Cc: "Lukas Kahwe Smith" , "Karoly Negyesi" , internals@lists.php.net Message-ID: <4022974B-4A13-4AB0-A282-973503200406@tekrat.com> To: Graham Kelly In-Reply-To: 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: Thu, 6 Nov 2008 10:37:02 -0800 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: shire@tekrat.com (shire) On Nov 5, 2008, at 7:22 AM, Graham Kelly wrote: > Hi, > > I played with a patched version of compare_function with this > optimization in it. Other then for strings it didn't seem to make > much of a difference. A quick test showed that in an average php > application only about 0.15% of calls to compare_function actually > have the same op1 and op2. Considering it doesn't make much of a > difference for anything except string comparison (and maybe arrays?) > it probably isnt worth putting it in compare_function. This > certinally is not a common case and would only serve to add an extra > needless comparison and branch to the other 99% of calls to > compare_function. Also, it seems as if in most cases this type of > behavior could be detected and handled appropriatly at compile time > by a good optimizer. I started looking at this briefly, and agree with what you describe above. I was curious to see if anyone came back with any real world applications where they where hitting this scenario but it seems unlikely. > > > However, while the common compare_function call probably wouldent > gain anything from this, maybe it could be put in the > TYPE_PAIR(IS_STRING, IS_STRING) case or put into zendi_smart_strcmp > (which only seems to ever be called by the TYPE_PAIR(IS_STRING, > IS_STRING) case of compare_function). > > I havent played with the patched version of zend_hash_compare to see > if it might provide any real world savings. Though it appears as if > that function might see a significant improvement for these cases. Arrays and strings do seem to be the only real worth while comparisons for this type of optimization, but only because the costs of comparing long strings and large array lists make the savings more significant. I think it might be hard to see this in a real world application though, so it would be nice if someone could justify the change by showing test results. I'll try to bench Facebook's code base to see what we can get out of it. -shire