JsComponent::getScopedDependencies shouldn't get auto-saves when viewing a page

Created on 31 July 2025, 8 days ago

Overview

I started doing some profiling of XB for performance. Viewing an XB page took 228ms roughly. However I noticed 51x queries to key_value_expire. Which is where auto-saves live.

select ... from key_value_expire where ? > :now and ? in (:keys__0) and ? = :collection

Which I thought was weird: I was viewing the page as an anonymous user. JsComponent::getScopedDependencies is loading autosaves. It's pretty cheap but has a scaling problem. 17 calls was only 13ms, but someone could have 50 components. AutoSaveManager has a cache and on cache miss it hits the DB for the auto-save. If we're not editing the entity, there is no auto-save. Which means we always cache miss and hit the DB for no reason.

I had 198 calls to Memcached::getMulti as well.

The problem is that $dependencyAutoSave = $this->autoSaveManager->getAutoSaveEntity($js_component_dependency); is always called even if we're not in a preview. Later on in shouldLoadAssetFromAutoSave there is a preview check.

We should avoid loading auto-saves unless in preview when rendering components.

Proposed resolution

In renderComponent we should use an empty auto-save if not in preview:

  public function renderComponent(array $inputs, string $componentUuid, bool $isPreview = FALSE): array {
    $component = $this->getJavaScriptComponent();

    if ($isPreview) {
      $autoSave = $this->autoSaveManager->getAutoSaveEntity($component);
    } else {
      $autoSave = AutoSaveEntity::empty();
    }

This change brought my response time from 228ms to 106ms! My memcache calls went from 198 calls to 63 and call DB queries to key_value_expire were removed.

User interface changes

✨ Feature request
Status

Active

Version

1.0

Component

… to be triaged

Created by

πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024