Add Static Caching to IconSet

Created on 15 January 2024, 5 months ago

Problem/Motivation

When the icons module is configured with a very large amount of icons to choose from, the IconSelect widget/element takes an extremely long amount of time to load all icons server-side.

Steps to reproduce

  1. Configure one or more Icon sets to have a very large amount of icons to choose from (1000+)
    • One way to accomplish this is to use the Add support for FontAwesome ✨ Add support for FontAwesome Needs review issue patch and install the free FontAwesome set.
  2. Go to an Add Menu Link form (eg: /admin/structure/menu/manage/main/add)
  3. Wait a very long time for the page to load...
    • On my machine, with over 1900 icons, this can take up to 1.5 minutes

Proposed resolution

Enable static caching for the IconSet config entity.

The reason it is taking so long is because unlike content entities, config entities are not statically cached by default. This results in the logic in Icon::preRenderIcon() converting the string version of '#icon_set' to IconSet entities by loading the entity from the database for EVERY SINGLE ICON regardless of whether the icon set has previously been loaded from the DB.

Simply adding static_cache = TRUE to the annotations of IconSet will result in my 1.5 minutes above be reduced to 6 seconds, which still not great but exponentially improved.

This will not only help situations where the IconSelect element is used, but also improve performance for loading icons wherever they're displayed by not reloading the entity from the DB for every icon.

There shouldn't be any downsides to statically caching the configuration as they will never be altered within a single request.

Related issues:

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada mdolnik

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

Comments & Activities

Production build 0.69.0 2024