Closed
Description
Preconditions
- Magento develop branch (1856c28 - January 15 2017)
- PHP 7.0.14
Steps to reproduce
- Have a shop with a bunch of products with images assigned to them
- Run
bin/magento catalog:images:resize
Expected result
- The command should only produced images for the themes which are currently active in the frontend
- The command shouldn't produce multiple files which are binary exactly the same
Actual result
- The command produces files for all the installed themes, even if they aren't being used in the frontend
- 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:
- The command generates resized images for all themes, so if you are not using
Magento/blank
orMagento/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 - 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 theimage 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 onimage type
is important, but maybe I'm missing something?
Possible solution
- I created a PR over here: Only resize images for themes which are being used instead of all installed themes. #8142
- 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:
- Originally: 11 seconds, 165 files are generated.
After applying PR: 9 seconds, 135 files are generated - 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
Cannot reproduce the issue on the latest `2.4-develop` branchGate 2 Passed. Manual verification of the issue description passedGate 1 Passed. Automatic verification of issue format passedThe issue has been reproduced on latest 2.1 releaseThe issue has been reproduced on latest 2.2 releaseThe issue has been reproduced on latest 2.3 release