Improve caching around SchedulerManager::getPlugins() and SchedulerManager::getEntityFormIds

Created on 8 September 2025, about 2 months ago

Problem/Motivation

I frequently see scheduler_form_alter() show up in blackfire and while some reports around it are strange, there are definitely some very unusual things here.

getPlugins() uses a persistant cache for instantiated plugins. I'm fairly certain that's more expensive than just instantiating them, especially because there is only a persistent cache.

However, getEntityFormIds() is quite expensive, because it calls into each plugin, which loops over all bundles and loads them and so on.

And it's doing that not just once, but multiple times due to the multiple form ids checks.

Steps to reproduce

Proposed resolution

Change the persistent cache to a property in getPlugins() so it's done only once per request.

Instead, add caches to simple outputs, such as getEntityFormIds() and also those route methods, as they are apparently also called on every request, such as due to \Drupal\scheduler\Theme\SchedulerThemeNegotiator::applies. Since this caches have no variations and are small, they can go into the fast chained bootstrap or discovery bin. They will however need cache tags, for example for the bundle-based things.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

2.0

Component

Code

Created by

🇨🇭Switzerland berdir Switzerland

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

Merge Requests

Comments & Activities

  • Issue created by @berdir
  • 🇨🇭Switzerland berdir Switzerland

    As an additional improvement, I'd add a check to scheduler_form_alter() to see if this is even an entity form ($form_state->getFormObject() instanceof EntityFormInterface, at least for the methods that expect it.

  • 🇨🇭Switzerland berdir Switzerland

    I see this was already improved recently in Implement static caching around SchedulerManager::getPlugins() Active but I'd go further and remove the persistent cache completely.

  • Merge request !254improving caching for plugins and entity form ids → (Merged) created by berdir
  • 🇨🇭Switzerland berdir Switzerland

    Created a merge request with some suggestions.

    With the change in the other issue, it's better, but it still shows up in blackfire. Converting to only a property, getPlugins() no longer shows up at all, and by converting getEntityFormIds() to fast chained cache, scheduler_form_alter() is now no longer visible in blackfire as well.

    Additionally, I changed the getTypes() call to using the bundle info service, that's faster (loading all config entities just to get their ids is very expensive), and it would also work for entity types that don't use bundle config entities. That could also be skipped for this issue, didn't do DI and so on.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 446s
    #592880
  • Pipeline finished with Failed
    about 2 months ago
    Total: 536s
    #592893
  • 🇨🇭Switzerland berdir Switzerland

    Will need to check the failing tests.

  • Pipeline finished with Success
    about 1 month ago
    Total: 958s
    #595499
Production build 0.71.5 2024