-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Doubts about the code In UnboundedLocalCache.java #869
Comments
haha, yes. This is an optimization hack to return the results in the given key order, drop duplicate keys to avoid redundant lookups, and minimize allocations as a minor performance trick. The non-concurrent Java collections like In that method's usage, it iterates over the preallocated results and modifies the The trick is a little more helpful for Of course this is not style of code to write in normal application logic, but I thought that I could get away with this micro optimization for fun in my own code without any coworkers seeing and frowning at me in a pr had I done such non-sense in company code. 🙂 caffeine/caffeine/src/main/java/com/github/benmanes/caffeine/cache/UnboundedLocalCache.java Lines 147 to 168 in d084f2d
|
Note that when I make fun of my optimization hack here, it is also because being clever backfired. It exposed a bug in the Java 8 rewrite of |
It does highlight a snippet where we can switch from raw |
Caffeine is the best caching library I have ever used, and I am also learning the programming ideas contained in Caffeine.
When I use Caffeine, I found the
getAllPresent
method inUnboundedLocalCache.java
. Lines149 to 151
of this method first put several key-value pairs whose value is null in the HashMap. I want to know what the purpose of this operation is.The text was updated successfully, but these errors were encountered: