Performance comparison between ConcurrentMap and LoadingCache

Skip to first unread message

Boyuan Zhang

Feb 17, 2021, 7:26:28 PM2/17/21
to guava-discuss
Hi team,

I recently changed my application from using ConcurrentMap to LoadingCache to perform certain caching functionality and I noticed a runtime performance drop(roughly from 35 mins to 31 mins). I want to understand what exactly causes this performance improvement. So I'm reaching out to the group to see whether there is a performance comparison already between ConcurrentMap and LoadingCache.

Thanks for your help!

Benjamin Manes

Feb 17, 2021, 8:16:34 PM2/17/21
to Boyuan Zhang, guava-discuss
This depends on what your workload is doing. Guava's cache is built on top of Java 5's ConcurrentHashMap with a default concurrency level of 4. This setting is because that hash table is segmented into multiple smaller tables, so more segments allows for higher concurrency at a cost of a larger memory footprint. A setting of 64 is more appropriate for performance sensitive scenarios.

Java 8 rewrote the hash table implementation for a 2x speedup and no longer relies on coarse segmentation. To leverage this required a complete rewrite of Guava's cache, which was done in Caffeine. Given the ability to start from scratch and build on everything we learned in Guava, there are many other performance improvements that were planned but not realized in Guava's implementation. This rewrite has about 33% of the read throughput of an unbounded ConcurrentHashMap and can obtain a higher hit rate than Guava's LRU.

The last time that I performed an in-depth benchmark was in 2015, but I do not believe any changes have been dramatic enough to invalidate these results.

In short, first try increasing the concurrencyLevel and, if not satisfactory, then switch to Caffeine.

Project site:
This group:
This list is for general discussion.
To report an issue:
To get help:
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Boyuan Zhang

Feb 17, 2021, 8:43:04 PM2/17/21
to Benjamin Manes, guava-discuss
Thanks! That's really helpful!
Reply all
Reply to author
0 new messages