Skip to content

Catalog image resizing performance problems #8145

Closed
@hostep

Description

@hostep

Preconditions

  1. Magento develop branch (1856c28 - January 15 2017)
  2. PHP 7.0.14

Steps to reproduce

  1. Have a shop with a bunch of products with images assigned to them
  2. Run bin/magento catalog:images:resize

Expected result

  1. The command should only produced images for the themes which are currently active in the frontend
  2. The command shouldn't produce multiple files which are binary exactly the same

Actual result

  1. The command produces files for all the installed themes, even if they aren't being used in the frontend
  2. The command produced files multiple times which are binary exactly the same

Discussion

While trying to figure out why it takes over 12 hours to run the command bin/magento catalog:image:resize on a very beefy server with a Magento CE 2.1.2 shop with about 6500 products and 8500 images, I found a couple of performance problems in the code:

  1. The command generates resized images for all themes, so if you are not using Magento/blank or Magento/luma on the frontend, you still get images resized for those themes, and they take a lot of time to generate, so this is not good
  2. After fixing nr 1, I looked at the generated files and compared them using a hashing function to see if there were duplicated files in the result. And this turned out to be the case.
    It was always caused by a difference in the image type (thumbnail, small_image, image, ...). All the other parameters (width, height, keep frame, transparency, quality, ...) to generate a unique file are correct I think. But I don't think the distinction on image type is important, but maybe I'm missing something?

Possible solution

  1. I created a PR over here: Only resize images for themes which are being used instead of all installed themes. #8142
  2. In Magento\Catalog\Model\Product\Image::getMiscParams, remove the line:
    'image_type' => $this->getDestinationSubdir(),

Result

I ran a very small benchmark using a test shop with 3 products and 5 images in total. Only Magento/blank and Magento/luma themes are installed and only Magento/luma is active in frontend:

  1. Originally: 11 seconds, 165 files are generated.
    After applying PR: 9 seconds, 135 files are generated
  2. Originally: 11 seconds, 165 files are generated.
    After removing line mentioned above: 9 seconds, 130 files are generated

Combined result of both optimizations:

  • Originally: 11 seconds, 165 files are generated.
    After both optimizations: 7 seconds, 105 files are generated

I think this is a significant enough improvement for you guys to at least consider optimizing this :)

Thanks!

Metadata

Metadata

Assignees

Labels

Component: CatalogIssue: Cannot ReproduceCannot reproduce the issue on the latest `2.4-develop` branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions