eightshift-libs
eightshift-libs copied to clipboard
Cache Autowiring::buildServiceClasses into a transient
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:
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:
I will open up additional PRs for optimization opportunities if I notice them.