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

Performance problem on listings and widgets with Price box #26850

Open
ilnytskyi opened this issue Feb 12, 2020 · 19 comments
Open

Performance problem on listings and widgets with Price box #26850

ilnytskyi opened this issue Feb 12, 2020 · 19 comments
Assignees
Labels
Area: Pricing Area: Product CD Issue recommended for the contribution day Component: Catalog Component: Pricing Event: Global-Contribution-Day Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: PR in progress Reported on 2.4.0 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S1 Affects critical data or functionality and forces users to employ a workaround. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@ilnytskyi
Copy link
Contributor

Preconditions (*)

  1. 2.4-develop or any previous version

Usage of \Magento\Catalog\Block\Product\ListProduct::getProductPrice
in app/code/Magento/Catalog/view/frontend/templates/product/list.phtml or product boxes in widgets affects listing performance.
It calculates price for products again even if the values received from collection.
On the screenshot you can see that product items have price values.
Selection_047

Then when a product is rendered, magento starts to resolve the price
Selection_048

It does these steps:

  • Looks for price renderer
  • loads linked products for composite products
  • Resolve price type (it already available from collection)

Because the prices already available from the collection it's enough to render formatted price value (amount and currency) [e.g. 10.00 $]. But magento loads prices again does comparations and then renders it. Even when sort by price used.

Steps to reproduce (*)

  1. Render price box from the product collection on listing or search pages
  2. Use simple or composite products
  3. See that price boxes consumes a lot of time for price rendering by calling
    \Magento\Catalog\Block\Product\ListProduct::getProductPrice in the loop

Expected result (*)

  1. Prices are rendered faster
  2. Redundant loads and price comparations in ListProduct::getProductPrice are eliminated
  3. ListProduct::getProductPrice just formats given price float values. It does not resolve prices again
  4. Moreover it does not load linked/child products

Actual result (*)

  1. Prices are rendered slowly
  2. ListProduct::getProductPrice loads extra price data and performs comparations
  3. ListProduct::getProductPrice does not use data already available from collection, loads prices again
  4. ListProduct::getProductPrice loads child/linked products and performs redundant price resolve.
@m2-assistant
Copy link

m2-assistant bot commented Feb 12, 2020

Hi @ilnytskyi. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

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

For more details, please, review the Magento Contributor Assistant documentation.

@ilnytskyi do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Feb 12, 2020
@engcom-Delta engcom-Delta self-assigned this Feb 17, 2020
@m2-assistant
Copy link

m2-assistant bot commented Feb 17, 2020

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

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Delta engcom-Delta added Component: Catalog Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Feb 17, 2020
@ghost ghost unassigned engcom-Delta Feb 17, 2020
@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Feb 17, 2020
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Delta
Thank you for verifying the issue. Based on the provided information internal tickets MC-31591 were created

Issue Available: @engcom-Delta, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@verheesj
Copy link

Isn't this because the product in question is a configurable product?

@ilnytskyi
Copy link
Contributor Author

@verheesj
yes, but the problem is in its price renderer implementation

@vishvesshah vishvesshah self-assigned this Feb 29, 2020
@m2-assistant
Copy link

m2-assistant bot commented Feb 29, 2020

Hi @vishvesshah. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


@vishvesshah vishvesshah removed their assignment Feb 29, 2020
@sdzhepa sdzhepa added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Jun 22, 2020
@VladimirZaets VladimirZaets added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S1 Affects critical data or functionality and forces users to employ a workaround. labels Jul 28, 2020
@VladimirZaets
Copy link
Contributor

VladimirZaets commented Jul 28, 2020

Action items to fix:

  • Verify that recalculated data is the same as the data from the index table ( collection )
  • If data the same, refactor implementation to use data from the index (collection)
  • If not, investigate the reason why data is different

Action items to testing:

  • Test fix with all types of the price (Tire, special, catalog rule, layered navigation prices)

@magento-engcom-team magento-engcom-team added Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. and removed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. labels Oct 1, 2020
@sivaschenko sivaschenko added the CD Issue recommended for the contribution day label Oct 7, 2020
@magento-engcom-team magento-engcom-team added Reported on 2.4.0 Indicates original Magento version for the Issue report. Priority: P2 A defect with this priority could have functionality issues which are not to expectations. and removed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. labels Nov 13, 2020
@mrtuvn
Copy link
Contributor

mrtuvn commented Mar 24, 2021

This one still valid today. Hope someone can take a look at it

@Nuranto
Copy link
Contributor

Nuranto commented Aug 4, 2022

Hope we'll have a fix for this in 2.4.5 !

Note : I see that @engcom-Kilo's commit deals only with configurable products. We have the same issue with grouped products.
If this can help with grouped products, here is some trace from newrelic :
Capture d’écran 2022-08-05 à 14 03 52
Rest of the trace :
Capture d’écran 2022-08-05 à 14 10 14
Capture d’écran 2022-08-05 à 14 09 53

@Nuranto
Copy link
Contributor

Nuranto commented Sep 21, 2022

still valid on 2.4.5.
I think this issue should be upgraded to P1 priority.

@MTheProgrammer
Copy link
Contributor

MTheProgrammer commented Oct 28, 2022

Same here, prices are loaded separately for every product of the configuration.

EDIT:
One trace says that MSI is a bottleneck:
The plugin:
Magento\InventoryConfigurableProduct\Plugin\Model\Product\Type\Configurable\IsSalableOptionPlugin::afterGetUsedProduct
is called in: Magento\Catalog\Pricing\Render\FinalPriceBox::_toHtml

        if (!$this->salableResolver->isSalable($this->getSaleableItem())) {

Also this line might be slow as it check sku manually for every product:
Magento\InventorySales\Model\AreProductsSalable::execute

        foreach ($skus as $sku) {
            $isSalable = $this->isProductSalable->execute($sku, $stockId);
            $results[] = $this->isProductSalableResultFactory->create(
                [
                    'sku' => $sku,
                    'stockId' => $stockId,
                    'isSalable' => $isSalable,
                ]
            );
        }

isProductSalable calls composite stock resolvers in a loop which has major impact on the performance.

@lukutpg
Copy link

lukutpg commented Nov 11, 2022

I had also performance issue for configurable product which have almost 2000 simple products (Magento CE 2.4.4).
For me the most slow was function \Magento\InventoryConfigurableProduct\Plugin\Model\Product\Type\Configurable\IsSalableOptionPlugin::filterProducts, so I just overridden it with follow code:

--- vendor/magento/module-inventory-configurable-product/Plugin/Model/Product/Type/Configurable/IsSalableOptionPlugin.php   
+++ vendor/magento/module-inventory-configurable-product/Plugin/Model/Product/Type/Configurable/IsSalableOptionPlugin.php
@@ -106,15 +106,24 @@
      * @param array $isSalableResults
      * @return void
      */
-    private function filterProducts(array $products, array $isSalableResults) : void
+    private function filterProducts(array &$products, array $isSalableResults) : void
     {
+        $isSalableResultsTest = [];
+        foreach ($isSalableResults as $result) {
+            if (!$result->isSalable()) {
+                $isSalableResultsTest[$result->getSku()] = $result->isSalable();
+            }
+        }
+
+        if (empty($isSalableResultsTest)) {
+            return;
+        }
+
         foreach ($products as $key => $product) {
-            foreach ($isSalableResults as $result) {
-                if ($result->getSku() === $product->getSku() && !$result->isSalable()) {
-                    $product->setIsSalable(0);
-                    if (!$this->stockConfiguration->isShowOutOfStock()) {
-                        unset($products[$key]);
-                    }
+            if (array_key_exists($product->getSku(), $isSalableResultsTest)) {
+                $product->setIsSalable(0);
+                if (!$this->stockConfiguration->isShowOutOfStock()) {
+                    unset($products[$key]);
                 }
             }
         }

@MTheProgrammer
Copy link
Contributor

MTheProgrammer commented Nov 11, 2022

Exactly, MSI is querying every stock for every product. Another pain point is swatches renderer which loads all options for every configurable product on the listing.

@jakwinkler
Copy link
Contributor

Latest version of M2 has the same issue.

@hubertus2017
Copy link

hubertus2017 commented Mar 29, 2023

For google shopping we there upload each simple products of configured products with their prices and individual links to preselect the option, e.g.

https........html?ps=MTU4PTIxOCYxNTk9MjIy#158=218&159=222

When loading the page, for the first second it displays the "as From" price from the lowest price of another simple product of the configurable product. Later (3 second?) it renders the correct price of the simple product together with its swatches. But that's too late for the google shopping crawler. He takes the first displayed "from price", which is incorrect. this leads to penalties at google and wrong ads.

I looked into final_price.phtml files but it did not help. i believe the Magento_Catalog/js/price-box.js must be changed?

Either to get rid of the display of the "from price" and/or how to speed up the display of the correct price?

Magento ver. 2.4.4

@jlenzstaysafe
Copy link

Latest version of Magento Commerce. Performance cannot be this bad, this isn't acceptable. We're sadly looking at other platforms as a result. I really want to stick with Magento, but I honestly cannot make a good case for it when things like this always make it to production.

@ilnytskyi
Copy link
Contributor Author

@jlenzstaysafe try this module https://github.com/EcomDev/magento2-product-preloader
As claimed it fixes Price of configurable product on product list can be some sort of workaround

@jakwinkler
Copy link
Contributor

@ilnytskyi @jlenzstaysafe this module is just a one part, it still requires to create a custom module and optimization of SQL queries. But yes, using it you drop PLP page to under 700ms load time

@engcom-Hotel engcom-Hotel moved this to Pull Request In Progress in High Priority Backlog Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Pricing Area: Product CD Issue recommended for the contribution day Component: Catalog Component: Pricing Event: Global-Contribution-Day Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: PR in progress Reported on 2.4.0 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S1 Affects critical data or functionality and forces users to employ a workaround. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Status: Pull Request In Progress
Development

No branches or pull requests