Skip to content

Memory overhead

Ben Manes edited this page Aug 31, 2025 · 24 revisions

MemoryBenchmark estimates are performed using Java Agent for Memory Measurements and Java Object Layout to calculate the runtime size. The size may be affected by compressed references, object padding, etc. as determined by the JVM.

By forking Java 5's ConcurrentHashMap, Guava has a slight advantage with per-entry optimizations. This is especially evident when weak and soft reference caching is used. Caffeine must retain additional fields to remove a collected entry due to decorating a Java 8 ConcurrentHashMap.

Caffeine may lazily initialize or dynamically resize its internal data structures based on usage. This reduces the footprint in favor of using additional memory only as required to meet usage demands (e.g. throughput).

Unbounded

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 128 bytes 32 bytes 200 bytes 32 bytes
Guava 928 bytes 48 bytes 1,120 bytes 48 bytes

Maximum Size

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 1,296 bytes 64 bytes 1,368 bytes 64 bytes
Guava 1,280 bytes 64 bytes 1,528 bytes 64 bytes

Maximum Size & Expire after Access

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 1,328 bytes 72 bytes 1,424 bytes 72 bytes
Guava 1,280 bytes 64 bytes 1,528 bytes 64 bytes

Maximum Size & Expire after Write

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 1,360 bytes 80 bytes 1,456 bytes 80 bytes
Guava 1,440 bytes 80 bytes 1,696 bytes 80 bytes

Maximum Size & Refresh after Write

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 1,336 bytes 72 bytes 1,432 bytes 72 bytes
Guava 1,296 bytes 80 bytes 1,576 bytes 80 bytes

Maximum Weight

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 1,336 bytes 72 bytes 1,336 bytes 72 bytes
Guava 1,296 bytes 64 bytes 1,520 bytes 64 bytes

Expire after Access

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 1,160 bytes 72 bytes 1,256 bytes 72 bytes
Guava 1,280 bytes 64 bytes 1,528 bytes 64 bytes

Expire after Write

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 1,128 bytes 72 bytes 1,248 bytes 72 bytes
Guava 1,088 bytes 64 bytes 1,336 bytes 64 bytes

Expire after Access & after Write

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 1,208 bytes 88 bytes 1,304 bytes 88 bytes
Guava 1,440 bytes 80 bytes 1,696 bytes 80 bytes

Weak Keys

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 1,144 bytes 88 bytes 1,216 bytes 88 bytes
Guava 1,136 bytes 56 bytes 1,400 bytes 56 bytes

Weak Values

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 1,136 bytes 80 bytes 1,208 bytes 80 bytes
Guava 1,136 bytes 64 bytes 1,400 bytes 64 bytes

Weak Keys & Weak Values

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 1,184 bytes 112 bytes 1,256 bytes 112 bytes
Guava 1,312 bytes 72 bytes 1,504 bytes 72 bytes

Weak Keys & Soft Values

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 1,184 bytes 120 bytes 1,256 bytes 120 bytes
Guava 1,312 bytes 80 bytes 1,576 bytes 80 bytes

Soft Values

Cache MemoryMeter ObjectLayout
Baseline Per Entry Baseline Per Entry
Caffeine 1,136 bytes 88 bytes 1,208 bytes 88 bytes
Guava 1,136 bytes 72 bytes 1,400 bytes 72 bytes
Clone this wiki locally