Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve product export performance #1602

Merged
merged 6 commits into from
Aug 14, 2015
Merged

Improve product export performance #1602

merged 6 commits into from
Aug 14, 2015

Conversation

convenient
Copy link
Contributor

The Bug

I discovered this bug in EE 1.14 while investigating it for a client. The same problem exists in Magento 2.

It boils down to the fact that as the number of categories and attributes increases the vanilla Magento product export gets significantly slower. All due to the bottleneck of the PHP array_intersect function.

The array_intersect function has remained largely unchanged from 5.3 to 5.5, so this problem will likely affect most versions of magento.

Based on my reading on stackoverflow and elsewhere I tried replacing array_intersect with a combination of array_combine and array_intersect_key, and saw that it greatly improved performance. The full product export for the client dropped from ~10 minutes to ~2 minutes.

Replication

My (not very scientific) method of testing and replicating this locally was to install magento/module-sample-data at 1.0.0-beta.

As this sample data was not enough to trigger the array_intersect bottleneck, I programatically added another 2500 categories. Giving me a grand total of 2540 categories.

Click 99b944e to see the script that generated them.

Profiling

I used xhprof to profile the export method, see the commits c6342a8 and cb4a42b.

In the following xhprof screenshots you can easily see that array_intersect takes first place as the bottleneck, once the code change is applied the biggest bottleneck sensibly goes back to PDOStatement::execute

Using array_intersect

using array_intersect

Using array_combine and array_intersect_key

using array_combine array_intersect_key

@kokoc
Copy link
Member

kokoc commented Aug 4, 2015

@convenient thank you for contribution! Great investigation! Internal reference: MAGETWO-41083

@convenient
Copy link
Contributor Author

@kokoc Thanks! You guys may want to back port this as a patch for 1.14 and 1.9 etc. 👍

@magento-team magento-team merged commit 3a7df2b into magento:develop Aug 14, 2015
@convenient convenient deleted the improve-product-export-performance branch August 14, 2015 13:24
@kokoc
Copy link
Member

kokoc commented Aug 17, 2015

@convenient your contribution is merged into develop branch. Thanks again!

@convenient
Copy link
Contributor Author

@kokoc Woo! Glad to see it got merged straight in. Thanks.

magento-team pushed a commit that referenced this pull request Oct 20, 2017
[EngCom] Public Pull Requests - 2.2-develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants