magento / magento/magento2

Slow performance when exporting CSV from the UI listing component with large dataset

Open
#40,232 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area: Order Component: UiComponents Issue: Confirmed Priority: P3 Reported on 2.4.8 Reproduced on 2.4.x Triage: Dev.Experience
Dominant language
PHP
Stars
12.2k
Forks
9.4k
PR merge metrics
No merged PRs in 30d

Description

Preconditions and environment
Q A
Magento version 2.4.8
PHP version 8.3.20
Summary

Slow performance when exporting CSV from the UI listing component with large dataset.

Steps to reproduce
  1. Place 10 orders
  2. Go to the admin
  3. Navigate SALES > Orders
  4. Add this line $countSelect->where('SLEEP(1) = 0'); in Magento\Framework\Data\Collection\AbstractDb::getSelectCountSql after the resets for the Order Grid instance.
public function getSelectCountSql()
{
        // ...    
        $countSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
        $countSelect->reset(\Magento\Framework\DB\Select::COLUMNS);

        if ($this instanceof \Magento\Sales\Model\ResourceModel\Order\Grid\Collection) {
            $countSelect->where('SLEEP(1) = 0');
        }
        // ... 
}
  1. Change the $pageSize from 200 to 1, in Magento\Ui\Model\Export\ConvertToCsv::__construct.
  2. In the order grid, select Export > CSV > Export.
Expected result

The processing will take more than 15-16 seconds. Also, multiple calls for Magento\Framework\Data\Collection\AbstractDb::getSelectCountSql.

Actual result

The processing should take more than 4-5 seconds. Also 2-3 calls for Magento\Framework\Data\Collection\AbstractDb::getSelectCountSql.

Additional information

AC-9607 moved the $searchResult->setTotalCount($totalCount); to after $searchResult->getItems();. It causes the unnecessary call for Magento\Framework\Data\Collection\AbstractDb::getSelectCountSql on each interaction making the CSV export slow.

Release note

No response

Triage and priority
  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the admin Sales > Orders CSV export using the steps provided, then inspect Magento\Framework\Data\Collection\AbstractDb::getSelectCountSql and Magento\Ui\Model\Export\ConvertToCsv::__construct. Review commit AC-9607 and trace the count calls during export; done means the unnecessary count calls are removed and large-dataset CSV export performance is improved.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.