question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove IntCache and LongCache for int and long keys

See original GitHub issue

Remove the IntCache and LongCache interfaces again. Since hotspot does escape analysis an autoboxed Integer is optimized away any way.

Plan:

  • Deprecate in 1.x
  • Remove in 2.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cruftexcommented, Jan 22, 2022

What I had with LongCache and IntCache was only half hearted. Some methods had an int lor long version, others did not. The whole API is too big to make it consistently. I just counted around 30 interface in the API using the type parameters K, V. The whole thing made a terrible mess. When doing it again, maybe with a complete separate and simpler API and then have primitive versions for every method in it consistently.

There is still an optimization present for int keys. When using int keys no object is stored. This did blend in quite well with the existing code base. The cache entry stores the hash code of the key object, identically like the HashMap. When there are only integer keys I use the hash code field directly for the key and do not store the object reference.

performance seems to be the main differentiator of Cache2k from other caching solutions.

Performance is the main selling point of every cache solution. With cache2k I managed to have faster access times than any other Java cache and proved that its possible to minimize the access overhead needed for cache eviction to a minimum while still getting an acceptable eviction efficiency that is mostly better than LRU. I update the https://cache2k.org/benchmarks.html page now with every version.

At the moment, big performance gains can be achieved, simply by using cache2k instead of another cache implementation. More optimization makes sense when there is a larger user base. Only then I can make a power plant superficial 😉

I am not saying that the performance is the best and therefore good enough. Further improvement is always good, however I need to focus and prioritize. That optimization was a big slowdown for the further ongoing development.

But I admit that my explanation in the issue was rather thin. So now we have the longer version. Thanks for asking.

0reactions
maxim5commented, Jan 21, 2022

Thanks!

My hope is that this problem is solved in a generic way via JVM optimizations.

That is my hope as well.

I think it is still good to get simpler.

I agree with this argument. But there’s one nuance: performance seems to be the main differentiator of Cache2k from other caching solutions. Applications looking for best performance are likely to consider primitive keys, and to me that’s the counter-argument to maintain the extra complexity. And it’s surprising to see a feature removed based on a hypothesis that it doesn’t hurt the main “selling point”.

Unless, of course, boxing overhead is not significant in benchmarks, so there’s little reason to go for int or long keys even in performance critical classes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java Caching – cache2k 1.1.2.Alpha
IntCache and LongCache for int and long keys, plus IntKeyValueSource and LongKeyValueSource; Cache2kBuilder.getManager() returns the cache manager; Cache.
Read more >
Optimize cache with multiple keys in c# - remove duplication ...
The first would be ConcurrentDictionary<string, int> (or whatever unique id applies to your model object) and would contain your key values.
Read more >
Cache2kBuilder (cache2k API 1.3.1.Alpha API) - javadoc.io
To create a cache from a known configuration in a specified cache manager, use: CacheManager manager = ... CacheConfiguration<Long, List<String>> config = ......
Read more >
Java Integer Cache - GeeksforGeeks
for ( int var3 = 0 ; var3 < cache.length; ++var3) { ... the facility to cache other objects also for Example like...
Read more >
CacheStream (Infinispan JavaDoc 11.0.16.Final API)
The performance is most affected for the key aware operations iterator() ... stateless function to apply to each element; Returns: the new long...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found