Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67629 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18252 invoked from network); 4 Jun 2013 18:53:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jun 2013 18:53:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:36656] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/C0-11673-F973EA15 for ; Tue, 04 Jun 2013 14:53:20 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 171C070000B5; Tue, 4 Jun 2013 19:53:16 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id grNKyXN28Sp7; Tue, 4 Jun 2013 19:53:15 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp2.ist.utl.pt (Postfix) with ESMTP id A15CF70000B2; Tue, 4 Jun 2013 19:53:15 +0100 (WEST) Received: from damnation.nl.lo.geleia.net (a80-101-138-144.adsl.xs4all.nl [80.101.138.144]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 9F9F32007303; Tue, 4 Jun 2013 19:53:13 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Dmitry Stogov" Cc: "PHP Internals" , "Zeev Suraski" , "Gadi Goldbarg" References: Date: Tue, 04 Jun 2013 20:53:08 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: User-Agent: Opera Mail/12.15 (Linux) Subject: Re: strtr() performance degradation From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Mon, 03 Jun 2013 10:55:16 +0200, Dmitry Stogov wrote: > I didn't look into the code yet (and really don't like to do it), but we > just noticed terrible performance degradation of strtr() function between > 5.4.11 and 5.4.15 coming probably after your changes. > > $ cat strtr.php > function foo() { > for ($i = 0; $i < 100000; $i++) { > strtr("abcdefgh", array("a"=>"11", "g"=>"22")); > } > } > foo(); > Your example is basically a worst-case scenario of the new algorithm and a best-case scenario of the old one. The new algorithm has a more costly preprocessing step and its gains are the smallest when the minimum pattern size is 1. That combined with a very short text makes the cost of the preprocessing step dominate. For strtr(str_repeat("abcdefgh", 50), ...) the results are very close and for 100 repeats the new algorithm is already faster. It also does not have cases of multi-second runs in relatively small inputs like the old algorithm (see https://bugs.php.net/bug.php?id=63893 ); you're talking about function calls that still execute in around 7 microseconds. That said, there certainly is an argument for using the old algorithm for short inputs, as its preprocessing step is much cheaper. It will require some experimentation in order to determine the cutoff, but if you think it's important I can do it (you're welcome to do it as well). Regards -- Gustavo Lopes