Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67630 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23093 invoked from network); 4 Jun 2013 20:12:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jun 2013 20:12:46 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain zend.com from 209.85.220.181 cause and error) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.181 mail-vc0-f181.google.com Received: from [209.85.220.181] ([209.85.220.181:52462] helo=mail-vc0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CB/00-22227-C3A4EA15 for ; Tue, 04 Jun 2013 16:12:45 -0400 Received: by mail-vc0-f181.google.com with SMTP id lf11so542231vcb.40 for ; Tue, 04 Jun 2013 13:12:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-gm-message-state; bh=qaSyD3RH9TYCnyv2Tlx6T9jl9w2BbFoC5ZZ0rzugE3s=; b=b0kHPwm3/N/iR+qI4H/6OXGSJRDCQFyg9V75CW9/KoXjzZBdMh1n7j0qbOlsc+yeto XfxRjg3YNKB1xEFQ+OB6g+2DbPk2HK+sJNu1h9FvRk9SPreKltIpAT0+IOxJ9UAePgmH p0YK4tEGRWcO6Npr1NRhc5DLzUvqaQf2NLX5hgYY1Yj9vsw5Bj8ek53DoNkQ0o8klcLH m7iALIpZrhAVtLRFlOjETHDavVuIMDlrperQg/tKKGiZWcwW2TTW63MVqjLkj4LGaErR 3XztpgpUL5mZeNYqByFg7CzYkc6mdHe/hD6fqO28ABthkVCu0AEKgQJ6cBEajbxHUL2o c6EQ== MIME-Version: 1.0 X-Received: by 10.220.111.133 with SMTP id s5mr19390840vcp.63.1370376761964; Tue, 04 Jun 2013 13:12:41 -0700 (PDT) Received: by 10.52.73.67 with HTTP; Tue, 4 Jun 2013 13:12:41 -0700 (PDT) In-Reply-To: References: Date: Wed, 5 Jun 2013 00:12:41 +0400 Message-ID: To: Gustavo Lopes Cc: PHP Internals , Zeev Suraski , Gadi Goldbarg Content-Type: multipart/alternative; boundary=047d7b33dd361b104004de59b4bd X-Gm-Message-State: ALoCoQmBjkd6Ie2kz4Uxh0X8TfJ1sDTFWlaa0lYRsKDpW0HJUK1OTm1A+4k/f6EJLt7GAIK9gduUse4ZvHPH+sW+r7Mcc1s+qr2aUqkSKhkFup9txL3NDMZEuw6BrQupkvMYDTCq/9/8 Subject: Re: strtr() performance degradation From: dmitry@zend.com (Dmitry Stogov) --047d7b33dd361b104004de59b4bd Content-Type: text/plain; charset=UTF-8 Hi Gustavo, This "good" algorithm that doesn't work well for "worse" cases makes about 15% slowdown of ZF2 based applications. It also slowdowns wordpress and other apps, but not so significantly. It's definitely doesn't work well for real-life applications :( Something must be dome (e.g. usage of old or new algorithms depending on different argument patterns). Thanks. Dmitry. On Tue, Jun 4, 2013 at 10:53 PM, Gustavo Lopes wrote: > 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 > --047d7b33dd361b104004de59b4bd--