Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41848 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43182 invoked from network); 11 Nov 2008 00:09:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Nov 2008 00:09:34 -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:44167] helo=sizzo.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/B8-34173-C3DC8194 for ; Mon, 10 Nov 2008 19:09:33 -0500 Received: from [172.24.57.110] (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 EB10F6D4A0E; Mon, 10 Nov 2008 16:09:29 -0800 (PST) To: Stan Vassilev | FM In-Reply-To: <140FB8F69197441FAB5F45A64FDA946E@pc> X-Priority: 3 References: <7e270cea0810191211w2cb77075y5e0ad78c2f7306f7@mail.gmail.com> <243C7392-C6A0-4EE8-8AAA-34964E78D453@tekrat.com> <4022974B-4A13-4AB0-A282-973503200406@tekrat.com> <38820B1D-6D5F-4B42-9FEE-0CDF23142A57@tekrat.com> <140FB8F69197441FAB5F45A64FDA946E@pc> Message-ID: <753B18C7-AC2F-4C96-B9CF-9FF5A042B96C@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: Mon, 10 Nov 2008 16:09:29 -0800 Cc: X-Mailer: Apple Mail (2.929.2) Subject: Re: [PHP-DEV] An optimization idea From: shire@tekrat.com (shire) On Nov 10, 2008, at 2:32 PM, Stan Vassilev | FM wrote: >> I just ran a quick benchmark on this and I'm not seeing a >> significant real world change for Facebook's codebase. (definitely >> less than 1%) This was a pretty small test, without a lot of code >> execution, so I could see other applications doing better. I'm >> pretty neutral on this one, it's not a really big change so might >> be worth adding if it's going to give a few applications out there >> a gain, but I couldn't see doing this everywhere of course. >> >> -shire > > > Hi, > > Something that could give arrays a boost would be to: > > - pool all string literals in each file > - give each stringl iteral an id (unique in the loaded environment) > - bind early all array access with string literals (a common > occurence), so they don't need to be resolved with a hashmap lookup, > but rather, a direct stirng literal id lookup. > > The benefit of this approach are: > > - There's no need to generate a hashmap in the first place > - String literal id-s are unique integers and have no conflicts, so > no need to do conflict resolution. This wouldn't really help with the case here of "if ($array1 == $array2)..." though right? (not to say it's not good, just making sure I understand ;-) ). It sounds like this would only work if the array contents where static though, as you're mapping a constant string to the contents of the hash (or did I misunderstand and you'd be mapping string const. values to hash IDs?). I am at the point now where my #1 item CPU wise is my hash function. I'm working on finding a slightly faster implementation, but I'm also playing with having a hash value stored in every zval so that the hash function call can be skipped if we've already ran it once. The problem that comes into play here is that there's no central code to update or clear the hash if the string or contents of the zval change. Of course, doing this with constant values would be easier to accomplish and could be done at compile time, and like you say this is a pretty common scenario. -shire