Slow performance when exporting CSV from the UI listing component with large dataset
Nobody has claimed this yet.
- 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
- Place 10 orders
- Go to the admin
- Navigate
SALES>Orders - Add this line
$countSelect->where('SLEEP(1) = 0');inMagento\Framework\Data\Collection\AbstractDb::getSelectCountSqlafter 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');
}
// ...
}
- Change the
$pageSizefrom 200 to 1, inMagento\Ui\Model\Export\ConvertToCsv::__construct. - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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