Mantis - Quercus
Viewing Issue Advanced Details
3195 major always 12-24-08 21:52 12-27-08 15:40
koreth  
ferg  
normal  
closed 4.0.0  
fixed  
none    
none 4.0.0  
0003195: Anchored regexes take time proportional to subject string size
<?php
$sizes = array(1000, 10000, 100000, 1000000, 10000000);
foreach ($sizes as $size) {
  $str = str_repeat('abcde', $size);
  $start_time = microtime(true);
  $match = preg_match('/x/A', $str);
  $end_time = microtime(true);
  printf("size %d took %0.6fsec
\n", $size, $end_time - $start_time);
}

In regular PHP, each run takes more or less the same amount of time. In Quercus, each run takes longer than the last by a factor of 10.

The behavior is also there if you use /^x/ instead of /x/A to anchor the regex.

This is making some of our on-the-fly JavaScript rewriting run so slowly the scripts time out.

Notes
(0003674)
koreth   
12-24-08 22:04   
One other note is that this only seems to be the case for failed matches. If a match succeeds it does so right away.
(0003676)
ferg   
12-27-08 15:40   
php/4e82