magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.55k stars 9.32k forks source link

Please fix the N+1 Query antipattern which significantly slows down cart page when you have Customer Address "custom attributes" #35578

Open peteracs opened 2 years ago

peteracs commented 2 years ago

Preconditions and environment

Steps to reproduce

  1. Create 3 new customer address custom attributes
  2. Go to checkout page. The performance drops by at least 2 seconds

I did profiling and found the culprit.

vendor/magento/module-customer/Model/Address/CustomAttributesProcessor.php

Line 51

            foreach ($customAttributes as $customAttributeCode => $customAttribute) {
                $attributeOptionLabels = $this->getAttributeLabels($customAttribute, $customAttributeCode);
                if (!empty($attributeOptionLabels)) {
                    $customAttributes[$customAttributeCode]['label'] = implode(', ', $attributeOptionLabels);
                }
            }

As you can see, there is a foreach here, which will go to "getAttributeLabels" and then $this->attributeOptionManager->getItems()' finally vendor/magento/module-eav/Model/Entity/Attribute/OptionManagement.php line 209 $attribute = $this->attributeRepository->get($entityType, $attributeCode);

So if you have 5 attributes, instead of having 1 SQL query, it will have 5 SQL query ... This is huge performance impact on checkout page

Expected result

Fast checkout

Actual result

When a lot of customer address custom attributes exists, the performance significantly drops on checkout page due to a foreach loop that triggers SQL one by one instead of having one SQL for customer address custom attributes

Additional information

No response

Release note

No response

Triage and priority

m2-assistant[bot] commented 2 years ago

Hi @peteracs. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] commented 2 years ago

Hi @engcom-Dash. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:


engcom-Dash commented 2 years ago

Hello @peteracs ,

We have tried to reproduce the issue in Magento 2.4.3 the issue is not reproducible. Please refer the below screenshot for the reference;

Screenshot from 2022-06-06 15-58-31

Screenshot from 2022-06-06 15-58-44 Screenshot from 2022-06-06 15-58-41

We have followed the below steps in order to reproduce the issue: 1.Create 3 new customer address custom attributes 2.Go to checkout page. 3.Order Placed Sucessfully Let us know in case we have missed anything.

Thanks!!!

peteracs commented 2 years ago

@engcom-Dash Did you check the performance before and after the 3 new customer address custom attributes? It was seriously hit.

engcom-Dash commented 2 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Dash. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Dash, here is your Magento Instance: https://ded87a9fce5085f9f92804529003b181.instances.magento-community.engineering Admin access: https://ded87a9fce5085f9f92804529003b181.instances.magento-community.engineering/admin_05d0 Login: 32325df9 Password: a3962e56fb58

engcom-Dash commented 2 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Dash. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Dash, here is your Magento Instance: https://ded87a9fce5085f9f92804529003b181.instances.magento-community.engineering Admin access: https://ded87a9fce5085f9f92804529003b181.instances.magento-community.engineering/admin_d01b Login: 9ed5a8c4 Password: bc46461183e6

engcom-Dash commented 2 years ago

Hi @peteracs , We are Getting Same Results Like the performance drops occurred. so We are Confirming the Issue. Here i Attached Screenshot For Reference. Screenshot from 2022-06-22 14-54-54