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

Partial thread safe (merge #154 first) #155

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

agentgt
Copy link
Contributor

@agentgt agentgt commented Nov 28, 2023

@samskivert

This PR builds on top of #154 . Merge that one first and I will rebase it on master and then you can merge it.

It fixes two problems:

  • _template should be volatile regardless of locks
  • a lock is used to load the partial template only once

Without the lock in a highly threaded environment the template can re-parsed an overwhelming amount of times.

For example the unit test code shows how the template can be loaded and parsed 63 times!

With the advent of Virtual Threads in JDK 21 you can have this happen way more often and if the template is coming from a database call this can be very expensive and outweighs the additional overhead of a lock (in almost all cases regardless of where the template comes from).

If you are wondering why _template never had threading problems (e.g. NPE on _template being null) not being volatile is because in 64 bit platforms all references are inherently atomic but this is not the case for 32 bit platforms like Raspberry PI or other JVM implementations.

@agentgt agentgt mentioned this pull request Nov 28, 2023
@agentgt agentgt force-pushed the partial_thread_safe branch from cf7773d to ab4bcb7 Compare November 29, 2023 14:04
@agentgt
Copy link
Contributor Author

agentgt commented Nov 29, 2023

@samskivert You can merge now. PR is now rebased onto master.

@samskivert samskivert merged commit fe6ef9c into samskivert:master Nov 29, 2023
4 checks passed
@agentgt agentgt deleted the partial_thread_safe branch November 30, 2023 16:46
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.

2 participants