Problem/Motivation

Noticed in #3518179: Renderer::executeInRenderContext() needs to handle nested calls and suspended fibers but it turns out to be unrelated to that issue.

On a cold cache (tested with Umami), _ckeditor5_get_langcode_mapping() gets called multiple times, it has a persistent cache but not a static cache, meaning it makes potentially dozens of round trips to the cache backend that could be one if there are lots of big pipe placeholders.

We could move this to a service and then keep the mappings on a class property, then only fetch them from the cache once.

While individual cache gets aren't expensive, we do 472 cache gets on the Umami front page with a cold cache, and if each cache get is 0.3ms, that would take over 150ms.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3531600

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

catch created an issue. See original summary.

catch’s picture

Issue summary: View changes
berdir’s picture

Note: 25 of the 45 default cache bin lookups in \Drupal\Tests\demo_umami\FunctionalJavascript\OpenTelemetryAuthenticatedPerformanceTest::testNodePageAdministrator() are this. So we could save 24 of those in that scenario.

Always a bit awkward with those internal functions, which are then actually used in completely different places (hooks and the ckeditor plugin), we can't just inline it into the hooks class, we need to make it a service, maybe tagged with @internal. We could make it a private service, then it would be a separate object instance, with the shared memory cache instance.

We could also put this in discovery (probably additionally, 25 lookups to apcu with unserialize still costs us _something_), because it's tiny, frequently used and a single, stable cache ID.

berdir’s picture

Status: Active » Needs work

We could also do this without the OOP conversion, but we have to do this anyway, so why not together.

It's an internal function, no known calls, so I don't think we need a change record, kept the old function with a reference to this MR. Can't make it private due to the BC layer.

performance tests need to be fixed.

berdir’s picture

Status: Needs work » Needs review

Updated the performance tests.

catch’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Performance

This looks great, can't see anything else to complain about. We can convert the one constructor to property promotion separately.

Easy to forget this happens on every cold cache request regardless of whether ckeditor appears on the page or not - because it's called when building library definitions which is global.

nod_’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 2592e8ba422 to 11.x and ea0226fd568 to 11.3.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • nod_ committed ea0226fd on 11.3.x
    Issue #3531600 by catch, berdir: Refactor...

  • nod_ committed 2592e8ba on 11.x
    Issue #3531600 by catch, berdir: Refactor...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.