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 <glo...@nebm.ist.utl.pt>wrote:

> On Mon, 03 Jun 2013 10:55:16 +0200, Dmitry Stogov <dmi...@zend.com> 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
>> <?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<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
>

Reply via email to