Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache Autowiring::buildServiceClasses into a transient #440

Merged
merged 7 commits into from
Nov 22, 2024

Conversation

mbmjertan
Copy link
Collaborator

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 mbmjertan added the improvement Small improvement fixes, either readability or performance improvements label Oct 30, 2024
@mbmjertan mbmjertan self-assigned this Oct 30, 2024
dingo-d
dingo-d previously approved these changes Oct 31, 2024
@iruzevic
Copy link
Member

Thank you for the implementation; it’s a great idea! However, I wouldn’t make it a requirement to clear transients each time you deploy a manual thing. We already have manifest caching in the transients, along with cache busting based on the project version number and other factors. Since the Cache class is loaded before the Main class, I believe you could utilize the Cache class to get and set your transients effectively.

Copy link
Member

@iruzevic iruzevic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a comment about cache busting

@mbmjertan
Copy link
Collaborator Author

Awesome, I wasn't familiar with how that class was implemented! ❤️
I will take a look and familiarize myself with the implementation and try to utilize that.

@iruzevic
Copy link
Member

iruzevic commented Nov 6, 2024

@mbmjertan and progress here, you need help?

@mbmjertan
Copy link
Collaborator Author

Hi, I didn't have the time to tackle this, hopefully I will today

@mbmjertan mbmjertan requested review from iruzevic and dingo-d November 8, 2024 14:36
@mbmjertan
Copy link
Collaborator Author

Refactored to use AbstractManifestCache and added basic support for caching custom objects in AbstractManifestCache (but maybe a generic concrete caching implementation in Libs would make sense in the future). Please test this before merging.

@iruzevic
Copy link
Member

Looks like it is working. I will make a prerelease from develop branch for testing

@mbmjertan
Copy link
Collaborator Author

We deployed this onto staging with no issues

@mbmjertan mbmjertan requested review from iruzevic and removed request for iruzevic November 20, 2024 22:24
@iruzevic iruzevic merged commit ec9d140 into main Nov 22, 2024
8 checks passed
@iruzevic iruzevic deleted the feature/cache-service-classes branch November 22, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Small improvement fixes, either readability or performance improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants