Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex is slow #30

Open
agulabon11 opened this issue Jul 2, 2024 · 1 comment
Open

Regex is slow #30

agulabon11 opened this issue Jul 2, 2024 · 1 comment

Comments

@agulabon11
Copy link

agulabon11 commented Jul 2, 2024

The preg_match() in line 452 can be slow in PHP 7.4 (not in 8.1 afaict).

Sometimes it takes seconds to minutes to parse.

if (!preg_match('`^(/?)([a-z][^ >]*)([^>]*)>(.*)`sm', $t[$i], $m)) {

For some reason it struggles with a sequence of many short lines (100 lines, 10 characters each), followed by a sequence of very long lines (10 lines, 10k long each).
That sequence takes more than 1 minute to parse.

@agulabon11
Copy link
Author

agulabon11 commented Jul 2, 2024

Test code:

$t="";

for ($i=0; $i<100; $i++)
        $t .= "1234567890\n";

for ($i=0; $i<10; $i++) {
        $l = "";
        for ($j=0; $j<10000; $j++)
                $l .= "x";
        $t .= $l . "\n";
}

if (preg_match('`^(\/?)([a-z][^ >]*)([^>]*)>(.*)`sm', $t, $m)) {
  print("match");
}

It takes 15 seconds for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant