Views::getApplicableViews() initializes displays during route rebuilding etc.

Created on 29 May 2015, over 9 years ago
Updated 12 September 2023, 12 months ago

Problem/Motivation

Steps to reproduce:

1. Load admin/modules
2. drush cr
3. Enable a module
4. Look at profiling data for the form POST and the next page render - see two screenshots attached.

Views::getApplicableViews() runs for route rebuilding, menu link plugins, and menu local task plugins. All of these are global registries/caches that completely block normal page rendering for any other request (i.e. not a single themed request can be served until all items have finished building).

With the standard profile they are not great for performance, and they get significantly worse once you have more views enabled on a site.

Note this is currently worse in HEAD due to #2495073: Views feed display plugin has to get all views data on init β†’ - but it makes sense to fix both issues independently of each other, however profiling will see more modest improvements depending on which gets fixed first.

Proposed resolution

Rather than initializing displays, check the config directly instead. This also avoids initializing the plugins which is itself expensive.

Remaining tasks

Get that working and profile before/after to see if it sufficiently fixes the issue.

User interface changes

None.

API changes

\Drupal\views\Views::getApplicableViews no longer returns view executables.

Before:

       $views = Views::getApplicableViews();
       foreach ($views as $data) {
         list($view, $display_id) = $data;
         $id = $view->storage->id();
         $this->viewsDisplayPairs[] = $id . '.' . $display_id;
      }

After:

       $views = Views::getApplicableViews();
       foreach ($views as $data) {
        list($view_id, $display_id) = $data;
        $this->viewsDisplayPairs[] = $view_id . '.' . $display_id;
     }
πŸ› Bug report
Status

Fixed

Version

8.0 ⚰️

Component
ViewsΒ  β†’

Last updated about 14 hours ago

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.

  • VDC

    Related to the Views in Drupal Core initiative.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024