Description
API(s)
Suppliers.memoize()
How do you want it to be improved?
Change it from synchronized
to ReentrantLock
Why do we need it to be improved?
Suppliers.memoize()
internally uses the double-checked locking idiom with the synchronized
keyword. Using synchronized
with virtual threads can cause thread pinning and slow down performance.
Example
Suppliers.memoize(() -> someLongRunningTask());
Current Behavior
Functions properly but causes performance degradation when used with virtual threads on Java 21
Desired Behavior
Performs optimally with virtual threads.
Concrete Use Cases
In our virtual thread enabled REST API, added lazy loading using Suppliers.memoize()
around some of our database interactions to improve performance but ended up seeing worse performance than going directly to database.
Checklist
-
I agree to follow the code of conduct.
-
I have read and understood the contribution guidelines.
-
I have read and understood Guava's philosophy, and I strongly believe that this proposal aligns with it.
Activity