Statically cache the list of fields during token generation

Created on 27 December 2018, over 5 years ago
Updated 17 January 2023, over 1 year ago

The function languagefield_field_map_filter() is used as an array filter callback in order to prevent some code duplication. The problem is that this function gets called in multiple loops each time an entity's tokens are loaded.

This can lead to this function being called several hundred thousand times in particular page requests (when these tokens are loaded).

This is an identical issue to the one reported (and fixed) for the addressfield module, see: #2416997. As such, parts of both this issue text and the solution have been copied from that issue.

We also do not use these tokens on the site, so I have not tested if the attached patch negatively impacts any token functionality, or if it has been correctly ported from the related solution. I can confirm that with this patch, our affected page load times were reduced by 25%, and the 240 000 function calls no longer appeared in the PHP code profiler.

πŸ“Œ Task
Status

Fixed

Version

1.7

Component

Code

Created by

πŸ‡ΏπŸ‡¦South Africa Gomez_in_the_South

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

Not all content is available!

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

No activities found.

Production build 0.71.5 2024