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

Fix resource expression calculation by removing volatile cache #3900

Merged
merged 3 commits into from
Feb 19, 2024

Conversation

petschki
Copy link
Member

@petschki petschki commented Feb 15, 2024

continued from here #3844 (comment)

@mister-roboto
Copy link

@petschki thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@petschki
Copy link
Member Author

@jenkins-plone-org please run jobs

@petschki
Copy link
Member Author

@jenkins-plone-org please run jobs

Copy link
Member

@mauritsvanrees mauritsvanrees left a comment

Choose a reason for hiding this comment

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

I agree with this approach. While you were working on this, I did some timings as well:

  • With the current (6.0.9) way, rendering both resource viewlets takes about 0.002 seconds total. Expressions do not work.
  • With the previous PR it is a bit more due to a not effective request cache key, but with a fix for that it is about the same. Expressions work, but memory usage increases.
  • With the current PR it becomes about 0.005, so it takes longer. Expressions work. Memory usage decreases (very) slightly because the volatile cache is gone. The code is easier.

All in all, I prefer this PR. Thanks!
Let's wait a bit till others have reviewed it as well.

Side note: most likely, on a production site, the resource viewlets are calculated once on a context, and then the html of the page is cached in Varnish or similar, at least for anonymous visitors. So it does not matter too much if calculating these viewlets takes a bit longer.

Copy link
Contributor

@yurj yurj left a comment

Choose a reason for hiding this comment

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

LGTM

This really does what is expected, so +1

Optimizations:
Render time could be improved just caching the single webresource.render() method, using the registry modification time (_RESOURCE_REGISTRY_MTIME), if there's no condition.
99% of the resources has no condition, so we can cache the render() method. This method take most of the time on creating the path. The path does not depends on anything, it is always the same.

Maybe we've to check if the RAM cache here:

cache = queryUtility(ram.IRAMCache)

for cooked_expressions but I think they are not used at all.

@jensens jensens merged commit c624c17 into 6.0.x Feb 19, 2024
4 checks passed
@jensens jensens deleted the petschki-issue-3789-new branch February 19, 2024 09:24
@jensens
Copy link
Member

jensens commented Feb 19, 2024

@petschki Please do the same for 6.1

@petschki
Copy link
Member Author

will do 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants