Optimize LayoutBuilderIsActiveCacheContext::getCacheableMetadata()

Created on 29 July 2025, 5 days ago

Problem/Motivation

Profiling a site I'm seeing LayoutBuilderIsActiveCacheContext::getCacheableMetadata() take around 40ms on a dynamic page cache hit.

It does some config entity loading and a couple of entity queries - it might be possible to cache the results of that.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

📌 Task
Status

Active

Version

11.0 🔥

Component

layout_builder.module

Created by

🇬🇧United Kingdom catch

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Comments & Activities

  • Issue created by @catch
  • First commit to issue fork.
  • @danielveza opened merge request.
  • 🇳🇿New Zealand danielveza Brisbane, AU

    Had a bit of a play with this, just trying out an alternate approach. I don't think we need to run all the entity queries at all for getting the cache data. We already know the display we want to cache just by the entity & entity type ID

    The only thing we might lose here by loading the entity directly is that the alter hook might not run. If thats an issue we can also run the alter hook here potentially 🤔

  • 🇳🇿New Zealand danielveza Brisbane, AU

    Hmm not as convinced on this after some more changes to get tests running. Got a passing PR up anyway. NavigationContentTopTest had a ~12% increase in speed with the new PR averaging out over 3 runs locally.

  • 🇬🇧United Kingdom catch

    On the specific site I'm testing with, this works if I change 'full' to 'default' when attempting to load the display, but otherwise it still falls back to ::getDisplay(). This probably isn't viable because it's specifically looking for 'full' in ::getDisplay(). Including an xhprof screenshot showing a definite improvement when it 'works' though.

Production build 0.71.5 2024