Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64962 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74825 invoked from network); 15 Jan 2013 00:13:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jan 2013 00:13:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=christopher.jones@oracle.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=christopher.jones@oracle.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain oracle.com designates 156.151.31.81 as permitted sender) X-PHP-List-Original-Sender: christopher.jones@oracle.com X-Host-Fingerprint: 156.151.31.81 userp1040.oracle.com Received: from [156.151.31.81] ([156.151.31.81:51417] helo=userp1040.oracle.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 52/EE-22727-A3F94F05 for ; Mon, 14 Jan 2013 19:13:47 -0500 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by userp1040.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id r0F0Dg5W027253 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 15 Jan 2013 00:13:43 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r0F0DgaM002834 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 15 Jan 2013 00:13:42 GMT Received: from abhmt105.oracle.com (abhmt105.oracle.com [141.146.116.57]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r0F0DfkR022236; Mon, 14 Jan 2013 18:13:41 -0600 Received: from [10.187.91.52] (/10.187.91.52) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 14 Jan 2013 16:13:41 -0800 Message-ID: <50F49F34.4040204@oracle.com> Date: Mon, 14 Jan 2013 16:13:40 -0800 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: Gustavo Lopes CC: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Source-IP: ucsinet21.oracle.com [156.151.31.93] Subject: Re: [PHP-DEV] strtr vs. str_replace runtime From: christopher.jones@oracle.com (Christopher Jones) On 01/14/2013 01:55 PM, Gustavo Lopes wrote: > On Wed, 09 Jan 2013 23:45:03 +0100, Gustavo Lopes wrote: > >> On Thu, 03 Jan 2013 11:40:31 +0100, Gustavo Lopes wrote: >> >>> The algorithm behaves very poorly in this case because at each position of the text, all the substrings starting there and with size between m and n (where m is the size of the smallest pattern and n is the largest) are checked, even if there are only >>> two patterns with size m and n. We could fix this easily by building a set of the pattern sizes found and try only with those. The hashing of the substrings could also be improved; we don't have to recalculate everything when we advance in the text. >>> >> >> Both optimizations (the hash rolling and limiting the substrings hashed on each iteration) worked quite well. >> >> But I got much better results with another algorithm [1], so I'm going to merge the branch with it [2] instead. > > OK, so now the plan is to merge this onto 5.4: > > https://github.com/cataphract/php-src/compare/php:PHP-5.4...cataphract:strtr_wu94_54 > > And this to 5.5: > > https://github.com/cataphract/php-src/compare/php:PHP-5.5...cataphract:strtr_wu94_55 > > The difference is that the 5.4 version does not introduce zend_qsort_r() and instead has dedicated simple heap sort. > > Any thoughts on this? > Despite temptation, I'm still erring on the side of merging to 5.5+ only. My argument is based on the potential for regressions (behavior and performance), added code maintenance issues, merge effort etc. The ability to differentiate the benefits of PHP 5.5 over 5.4, and promote migration to 5.5 will also be improved. Chris -- christopher.jones@oracle.com http://twitter.com/ghrd Newly updated, free PHP & Oracle book: http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html