Skip to content

Performance regression in PHP 8.3 #11507

Closed
@andypost

Description

@andypost

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions