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

Performance regression in PHP 8.3 #11507

Closed
andypost opened this issue Jun 22, 2023 · 4 comments
Closed

Performance regression in PHP 8.3 #11507

andypost opened this issue Jun 22, 2023 · 4 comments

Comments

@andypost
Copy link
Contributor

andypost commented Jun 22, 2023

Description

The following code:

<?php

$post_max_size = 8 * 1024 * 1024;

function generateFile($filename, $width, $lines, $type = 'binary-text') {
  $text = '';
  $t0 = microtime(TRUE);

  for ($i = 0; $i < $lines; $i++) {
    // Generate $width - 1 characters to leave space for the "\n" character.
    for ($j = 0; $j < $width - 1; $j++) {
      switch ($type) {
        case 'text':
          $text .= chr(rand(32, 126));
          break;

        case 'binary':
          $text .= chr(rand(0, 31));
          break;

        case 'binary-text':
        default:
          $text .= rand(0, 1);
          break;
      }
    }
    $text .= "\n";
    $t1 = microtime(TRUE);
    print "Iteration $i - " . (($t1 - $t0) * 1000) . ' ms' . "\n";
    $t0 = $t1;
  }

  // Create filename.
  $filename = '/tmp/' . $filename . '.txt';
  //file_put_contents($filename, $text);
  return $filename;
}

echo generateFile('exceeding_post_max_size', ceil(($post_max_size + 1024) / 1024), 1024);

Resulted in this output in previous versions:

...
Iteration 1016 - 1.060962677002 ms
Iteration 1017 - 1.3351440429688 ms
Iteration 1018 - 1.4958381652832 ms
Iteration 1019 - 1.5652179718018 ms
Iteration 1020 - 1.133918762207 ms
Iteration 1021 - 1.3449192047119 ms
Iteration 1022 - 1.0910034179688 ms
Iteration 1023 - 2.5720596313477 ms

But I'm getting this output instead:

Iteration 0 - 1.6670227050781 ms
Iteration 1 - 3.5400390625 ms
Iteration 2 - 5.9168338775635 ms
Iteration 3 - 8.7440013885498 ms
Iteration 4 - 11.125087738037 ms
Iteration 5 - 13.100862503052 ms
Iteration 6 - 14.358997344971 ms
Iteration 7 - 19.643068313599 ms
Iteration 8 - 21.284103393555 ms
Iteration 9 - 24.443864822388 ms
Iteration 10 - 29.021978378296 ms
Iteration 11 - 29.219150543213 ms
Iteration 12 - 29.844999313354 ms
Iteration 13 - 33.437013626099 ms
Iteration 14 - 35.980939865112 ms
Iteration 15 - 37.060976028442 ms
Iteration 16 - 40.301084518433 ms
Iteration 17 - 45.086860656738 ms
Iteration 18 - 47.156095504761 ms
Iteration 19 - 54.861068725586 ms
Iteration 20 - 59.279918670654 ms
Iteration 21 - 55.058002471924 ms
Iteration 22 - 62.628984451294 ms
Iteration 23 - 62.710046768188 ms
Iteration 24 - 66.666841506958 ms
Iteration 25 - 67.9612159729 ms
Iteration 26 - 73.35090637207 ms
Iteration 27 - 73.814868927002 ms
Iteration 28 - 81.268072128296 ms
Iteration 29 - 86.863994598389 ms
Iteration 30 - 86.045980453491 ms
Iteration 31 - 89.563131332397 ms
Iteration 32 - 93.811988830566 ms
Iteration 33 - 104.84790802002 ms
Iteration 34 - 103.92713546753 ms
Iteration 35 - 118.44992637634 ms
Iteration 36 - 117.29502677917 ms
Iteration 37 - 122.51305580139 ms
Iteration 38 - 147.05491065979 ms
Iteration 39 - 145.72691917419 ms
Iteration 40 - 145.61200141907 ms
Iteration 41 - 157.13310241699 ms
Iteration 42 - 132.14802742004 ms
Iteration 43 - 134.90295410156 ms
Iteration 44 - 139.23907279968 ms
Iteration 45 - 172.71780967712 ms
Iteration 46 - 156.75115585327 ms
Iteration 47 - 142.99201965332 ms
Iteration 48 - 142.3168182373 ms
Iteration 49 - 142.22002029419 ms
Iteration 50 - 147.85099029541 ms
Iteration 51 - 150.74706077576 ms
Iteration 52 - 183.83002281189 ms
Iteration 53 - 185.53805351257 ms
Iteration 54 - 156.80599212646 ms
Iteration 55 - 165.35997390747 ms
Iteration 56 - 180.59802055359 ms
Iteration 57 - 179.68106269836 ms
Iteration 58 - 180.39298057556 ms
Iteration 59 - 176.19895935059 ms

PHP Version

PHP 8.3.0-alpha2

Operating System

Alpinelinux, Ubuntu

@andypost
Copy link
Contributor Author

andypost commented Jun 22, 2023

https://3v4l.org/WciJK shows that previously it was a constant time

It makes 1 test of Drupal to hang forever with following strace

@iluuu1994
Copy link
Member

This seems to be due to 727e26f. @nielsdos I can investigate, if you aren't already.

nielsdos added a commit to nielsdos/php-src that referenced this issue Jun 22, 2023
When the code was moved to solve the uaf for memory overflow, this
caused the refcount to be higher than one in some self-concatenation
scenarios. This in turn causes quadratic time performance problems when
these concatenations happen in a loop.
@nielsdos
Copy link
Member

I was about to post a PR. It's actually bcuz of 7790ee8

@iluuu1994
Copy link
Member

@nielsdos Ah I see, that's my bad, thank you!

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

Successfully merging a pull request may close this issue.

3 participants