Optimize AssetResolver caching

Created on 24 April 2024, 8 months ago
Updated 18 May 2024, 7 months ago

Problem/Motivation

Follow-up from 📌 Return early in AssetResolver::getJsAssets() and AssetResolver::getCssAssets() when there are no libraries to load Needs review , I think we can improve it more, but it definitely needs to be an improvement compared to the new status quo from that issue vs how it was before, and two issues makes that easier to demonstrate.

There are two cases where AssetResolver::getJsAssets() is passed a list of libraries that only contain CSS. One is when there is no JavaScript on the page anywhere, the other is when a big pipe placeholder adds a library that only contains CSS.

In these cases, by moving some library filtering logic out of the cache, we can return early, and save both cache gets and sets when this happens.

When the request has some js libraries, we'll still need to get the cache, but it should also be overall more efficient in that case too:

By caching on the filtered list of libraries with irrelevant ones removed, if two pages have the same js libraries but different CSS libraries (very common), then the cache key is currently different because it uses the full list, but after this MR will be the same cid, because it will only care about the js libraries.

In the case where it doesn't otherwise improve the caching situation or return early, the question then is does the extra processing cause a regression? I double checked, and we already load the full library definitions (from a cache collector, which is in discovery and hence chained fast) when we call ::getLibrariesToLoad(). Because of this, it's just a foreach loop and some static caching extra which is worth it for less cache i/o and better hit rates.

The same is true for getCSSAssets() just slightly less, it will benefit when:
- only a js library is sent, which can happen on bigpipe requests.
- the same css libraries are sent, with different js libraries - can happen on any request.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Fixed

Version

10.3

Component
Asset library 

Last updated 1 day ago

No maintainer
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.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024