spatie / laravel-medialibrary

Associate files with Eloquent models
https://spatie.be/docs/laravel-medialibrary
MIT License
5.78k stars 1.08k forks source link

Imagick driver works super slow with v11 #3583

Closed aprokopenko closed 5 months ago

aprokopenko commented 7 months ago

Hi,

we just upgraded to v11 from v10. All working fine except conversions and image manipulations are working super slow (2 mins comparing to 1 second) with "imagick" driver.

We use PHP 8.2.15, imagick 3.7.0 (installed via pecl). Changing driver to gd provides better results, but still about 6-7 seconds, not 1 sec as before. We have feature tests, and now all tests with image manipulations processed about 130-150secs instead of 5-6secs.

I'm not sure how to reproduce the bug, here are our settings:

$this
    ->addMediaCollection('hero')
    ->useDisk($publicDisk)
    ->singleFile()
    ->registerMediaConversions(function (Media $media) {
        $this->addMediaConversion('backoffice')
            ->fit(...config('media-library.defaults_conversions.backoffice'))
            ->nonQueued();

        $this
            ->addMediaConversion('thumb')
            ->fit(...config('media-library.defaults_conversions.thumb'));

        $this
            ->addMediaConversion('hd')
            ->withResponsiveImages()
            ->fit(...config('media-library.defaults_conversions.hd'));

        $this->addMediaConversion('thumb_sm')
            ->fit(...config('media-library.offerings_conversions.thumb_sm'));
        $this->addMediaConversion('thumb_lg')
            ->fit(...config('media-library.offerings_conversions.thumb_lg'));
    });

and the configs:

    'defaults_conversions' => [
        'backoffice' => [Fit::Crop, 100, 50],
        'thumb' => [Fit::Crop, 720, 420],
        'hd' => [Fit::Crop, 1920, 1080],
    ],

    'offerings_conversions' => [
        'thumb_sm' => [Fit::Crop, 431, 307],
        'thumb_lg' => [Fit::Crop, 720, 775],
    ],
aprokopenko commented 7 months ago

We re-tested our API and found that it works fine, so the problem appears only when running feature tests. As a hotfix we set gd for tests for now, but it's very weird behavior. With v10 there are no such problems on any driver.

patinthehat commented 6 months ago

@aprokopenko Just to clarify, you mean when running your feature tests, not the feature tests included with this package? Thanks for following up on the issue as well! :+1:

timvandijck commented 6 months ago

We re-tested our API and found that it works fine, so the problem appears only when running feature tests. As a hotfix we set gd for tests for now, but it's very weird behavior. With v10 there are no such problems on any driver.

That's intresting. V11 has the updated spatie/image package under the hood where we replaced intervention/image with our own code. I would have expected that most of the "heaviness" comes from Imagick itself though, so I'm curious to what we do differently than intervention/image to cause a difference.

If anyone has ideas I would be happy to read them and optimize our package.