Skip to content

Magento_Persistent performance overhead on non-cart, non-checkout pages #39948

Open
@adamwaclawczyk

Description

@adamwaclawczyk

Summary

Preconditions (*)

  1. Products added to cart

Steps to reproduce (*)

  1. Enter PDP with profiler enabled
  2. Quote is not expired and the quote is fully loaded to check this, performance suffers

Expected result (*)

  1. persistent_quote observer does not load the quote before it's absolutely necessary

Actual result (*)

  1. persistent_quote is loading the full quote with expensive assignProducts function call

Magento_Persistent adds controller_action_predispatch event persistent_quote observer. On non-cart, non-checkout pages(e.g. PDP) it's loading quote and it impacts the TTFB significantly. Due to the observer's private function declarations, overriding the logic inside the observer class requires developers to add class preference or patch the observer class directly. There is no "ok" way to implement workaround for this.

Image


return (bool)$this->getQuote()->getIsPersistent();

Both of these calls could be simplified by checking the quote table data directly. The business logic will still be satisfied. If the quote has to be expired, then the quote probably needs to be still loaded fully.

Examples

class QuoteResourceWrapper
{
    public function __construct(
        private readonly ResourceConnection $resourceConnection
    ) {
    }

    public function isActive(?int $quoteId): bool
    {
        if (empty($quoteId)) {
            return false;
        }
        $table = $this->resourceConnection->getTableName('quote');
        $connection = $this->resourceConnection->getConnection();
        $select = $connection->select()
            ->from($table, 'is_active')
            ->where('entity_id = ?', $quoteId);

        return $connection->fetchOne($select) == true;
    }

    public function isPersistent(?int $quoteId): bool
    {
        if (empty($quoteId)) {
            return false;
        }
        $table = $this->resourceConnection->getTableName('quote');
        $connection = $this->resourceConnection->getConnection();
        $select = $connection->select()
            ->from($table, 'is_persistent')
            ->where('entity_id = ?', $quoteId);

        return $connection->fetchOne($select) == true;
    }
}

Proposed solution

Do not load quote fully if not needed.
I have prepared a sample class that could be used as a wrapper for getting the required data instead, see Examples

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”.

Activity

added
Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it
on May 28, 2025
m2-assistant

m2-assistant commented on May 28, 2025

@m2-assistant

Hi @adamwaclawczyk. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 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.

m2-assistant

m2-assistant commented on May 28, 2025

@m2-assistant

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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
    3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
    4. Verify that the issue is reproducible on 2.4-develop branch
    Details- 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.
removed their assignment
on May 28, 2025
self-assigned this
on May 29, 2025
m2-assistant

m2-assistant commented on May 29, 2025

@m2-assistant

Hi @engcom-Hotel. 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).
    2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
    3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
    4. Verify that the issue is reproducible on 2.4-develop branch
    Details- 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-Hotel

engcom-Hotel commented on May 29, 2025

@engcom-Hotel
Contributor

Hello @adamwaclawczyk,

Thanks for the report & collaboration!

We have tried to reproduce the issue in the latest development branch (Vanilla) i.e. 2.4-develop but it seems the issue is not reproducible for us. Please refer to the below screenshot for reference:

Image

Let us know if we missed anything.

Thanks

moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Boardon May 29, 2025

22 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: FrameworkComponent: PersistentIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.Reported on 2.4.xIndicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

Status

Ready for Development

Milestone

No milestone

Relationships

None yet

    Participants

    @adamwaclawczyk@engcom-Bravo@engcom-Hotel@engcom-November@github-jira-sync-bot

    Issue actions

      Magento_Persistent performance overhead on non-cart, non-checkout pages · Issue #39948 · magento/magento2