Improve performance of the AccessManager

Created on 9 August 2021, almost 3 years ago
Updated 3 October 2023, 9 months ago

Problem/Motivation

With the new plugin based approach to define layout builder permissions, you could very easily get hundreds of permissions with the new submodules enabled (just by adding a bunch of content types and block types). In the current setup, the access manager instantiates all plugins each time a permissions needs to be checked, and calls the applies() method on ALL plugins to see if they have a permission for a specific operation, layout, entity, bundle etc. This is very inefficient. The more blocks and sections are added to a page, the slower the layout builder loads. At the current time layout builder takes about 1 minute to load (I have xDebug enabled, but without the layout builder permission checks the page loads in 4 seconds).

Steps to reproduce

Enable some of the submodules.
Add some content types.
Add some block types.
Add some sections and blocks to a page.
Behold the slowness.

Proposed resolution

To improve the performance I would suggest to do the following:

  • Allow plugins to add things like layout, entity_type, bundle, block_type etc to the plugin definition (just like the operation).
  • Allow filters to be passed to LayoutBuilderPermissionPluginManager::getPermissionPlugins(), to filter plugins by their definition and only load/instantiate plugins that have an opinion on the access. This does similar things to the applies() method, but only checks very simple values in the plugin definition. The applies method should probably be kept for more fine-grained control.
  • Statically cache instantiated plugins (for a set of filters) and permanently cache a filtered lost of definitions for faster lookups.

Remaining tasks

In my current tests the page loads in about 4.4 seconds (again with xDebug enabled), about the same as having this module disabled entirely.

User interface changes

None

API changes

Extra data is added to the plugin definitions.

Data model changes

None

✨ Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands seanB Netherlands

Live updates comments and jobs are added and updated live.
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.69.0 2024