Performance Regression with Imagick between PHP 7.2 and 8.2

I’m noticing a significant performance difference when running the same Imagick script on PHP 7.2 versus PHP 8.2. Here are the results I’ve gathered:

  • PHP 7.2, ImageMagick 7.0.7, Imagick 3.44: 3.8 seconds

  • PHP 8.2, ImageMagick 7.1, Imagick 3.7: 13.32 seconds

Same spec machine, tested on windows and centos with similar results.

I’m wondering if anyone has encountered similar issues or knows why this change between PHP versions might be affecting Imagick’s performance so drastically? Or know any fixes for this? Below is the test script I’m using (it does this on other functions too not just distorts, this is just an example):

<?php

$startTime = microtime(true);

// Get script directory
$script_path = dirname(__FILE__) . "/";

$controlPoints = [
    1.5,
    0, 0, 355, 70,
    0, 3708, 337, 974,
    1380, 0, 657, 105,
    1380, 3708, 654, 956,
];

echo "Doing Distortion 1n";

$design = new Imagick($script_path . 'input.png');

// Apply distortion
try {
    $design->distortImage(Imagick::DISTORTION_POLYNOMIAL, $controlPoints, true);
} catch (Exception $e) {
    echo "Error applying distortion: " . $e->getMessage() . "n";
}

// Write the distorted image to an output file
$design->writeImage($script_path . "testoutput.png");

$endTime = microtime(true);
$executionTime = ($endTime - $startTime);

echo "Execution Time: " . $executionTime . " secondsn";