eightshift-libs icon indicating copy to clipboard operation
eightshift-libs copied to clipboard

Cache Autowiring::buildServiceClasses into a transient

Open mbmjertan opened this issue 3 months ago • 2 comments

Description

Using profiling we've gathered that we spend a lot of time in Autowiring::buildServiceClasses. In particular, we spent 14% of the whole page generation time just running the method for EightshiftForms.

Here's a screenshot from an Excimer-grabbed profile opened up in Speedscope on my local machine: Screenshot 2024-10-30 at 16 24 21

I added caching this into a transient using the project namespace as a unique key. This requires transients to be cleared on all deployments, and can cause breakage if manuallyDefinedDependencies is changed dynamically at runtime. This should probably be documented in eightshift-docs.

I should probably add a way to toggle this off. Do you prefer WP_ENVIRONMENT_TYPE, a special constant or both?

After this change, it's no longer noticeable in the profile and the whole registerServices method now takes less time than just the buildServiceClasses method used to: Screenshot 2024-10-30 at 16 31 00

I will open up additional PRs for optimization opportunities if I notice them.

mbmjertan avatar Oct 30 '24 15:10 mbmjertan