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

Performance problem whith checkout CompositeConfigProvider #32642

Closed ilnytskyi closed 3 years ago

ilnytskyi commented 3 years ago

Preconditions (*)

  1. any magento version 2.x.x, 2.4.x
  2. Magento core code and module vendors do not care about checking if certain features are enabled or not for checkout. See method https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Checkout/Model/CompositeConfigProvider.php#L35 Vendors add their config classes via DI then magento core code just retrieve all configs in the loop.

        $config = [];
        foreach ($this->configProviders as $configProvider) {
            $config = array_merge_recursive($config, $configProvider->getConfig());
        }
        return $config;

    It leads to performance degradation in checkout because some $configProviders perform requests to external services to init sessions or get some tokens. The issue seem to be complex, because we need either force all vendors to check internally if $configProvider is allowed or add possibility to configure $this->configProviders somewhere in admin panel. Now developers can only use DI or plugins for each $configProvider to disable it (or disable it per store).

I think that doing additional check would help to save some CPU and improve page time.

        $config = [];
        foreach ($this->configProviders as $configProvider) {
            if ($configProvider->isActive()) {
                  $config = array_merge_recursive($config, $configProvider->getConfig());
            }
        }
        return $config;

In case of Braintree or Dotpay services we may use only one of payments gateways, but the modules would perform up to 5 requests each. So our checkout page would load forever. Additionally CompositeConfigProvider used in both checkout/cart and /checkout pages. In many stores we finish purchase only on /checkout page. So those all requests on checkout/cart are not necessary.

Steps to reproduce (*)

  1. Install some payment modules
  2. Disable certain features or deactivate payment methods in a store e.g. Paypal/Braintree
  3. Open checkout/cart or checkout page
  4. Profile those pages with PHP SPX or Blackfire or other profiler
  5. Check how the configs are generated

Expected result (*)

  1. Disabled or inactive methods do not appear to perform any CPU costly operations
  2. No external request performed in Checkout/Model/CompositeConfigProvider.php https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Checkout/Model/CompositeConfigProvider.php#L35

Actual result (*)

Selection_581

  1. Requests can be seen in profile view.
  2. Page load time extended up to 2 seconds, depending how many requests to external services Braintree or other payment methods performed

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

ilnytskyi commented 3 years ago

GeneCommerce provided a patch for their Braintree module here https://github.com/genecommerce/module-braintree-magento2/pull/155/files

LuigiLazzari commented 3 years ago

I want to help here, but I'm at a loss, should I just implement this:

GeneCommerce provided a patch for their Braintree module here https://github.com/genecommerce/module-braintree-magento2/pull/155/files

On the core payment modules?

engcom-Lima commented 3 years ago

Hi @ilnytskyi

Can you please confirm about your query? is it got resolved?

m2-assistant[bot] commented 3 years ago

Hi @engcom-Lima. 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:

m2-assistant[bot] commented 3 years ago

Hi @engcom-November. 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-November commented 3 years ago

@ilnytskyi , We are closing this issue as there has been no latest update on the same. Thank you.