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 Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 262,288 bytes 32 bytes (32 aligned) 524,504 bytes 32 bytes (32 aligned)
Guava 263,008 bytes 48 bytes (48 aligned) 263,200 bytes 48 bytes (48 aligned)

Maximum Size

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 787,728 bytes 64 bytes (64 aligned) 787,848 bytes 64 bytes (64 aligned)
Guava 263,360 bytes 64 bytes (64 aligned) 263,608 bytes 64 bytes (64 aligned)

Maximum Size & Expire after Access

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 787,760 bytes 72 bytes (72 aligned) 787,904 bytes 72 bytes (72 aligned)
Guava 263,360 bytes 64 bytes (64 aligned) 263,608 bytes 64 bytes (64 aligned)

Maximum Size & Expire after Write

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 787,792 bytes 80 bytes (80 aligned) 787,936 bytes 80 bytes (80 aligned)
Guava 263,520 bytes 80 bytes (80 aligned) 263,776 bytes 80 bytes (80 aligned)

Maximum Size & Refresh after Write

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 787,768 bytes 72 bytes (72 aligned) 787,912 bytes 72 bytes (72 aligned)
Guava 263,376 bytes 80 bytes (80 aligned) 263,656 bytes 80 bytes (80 aligned)

Maximum Weight

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 525,624 bytes 72 bytes (72 aligned) 525,672 bytes 72 bytes (72 aligned)
Guava 263,376 bytes 64 bytes (64 aligned) 263,600 bytes 64 bytes (64 aligned)

Expire after Access

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 263,288 bytes 72 bytes (72 aligned) 263,432 bytes 72 bytes (72 aligned)
Guava 263,360 bytes 64 bytes (64 aligned) 263,608 bytes 64 bytes (64 aligned)

Expire after Write

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 263,256 bytes 72 bytes (72 aligned) 263,424 bytes 72 bytes (72 aligned)
Guava 263,168 bytes 64 bytes (64 aligned) 263,416 bytes 64 bytes (64 aligned)

Expire after Access & after Write

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 263,336 bytes 88 bytes (88 aligned) 263,480 bytes 88 bytes (88 aligned)
Guava 263,520 bytes 80 bytes (80 aligned) 263,776 bytes 80 bytes (80 aligned)

Weak Keys

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 263,272 bytes 72 bytes (72 aligned) 263,392 bytes 88 bytes (88 aligned)
Guava 263,216 bytes 40 bytes (40 aligned) 263,480 bytes 56 bytes (56 aligned)

Weak Values

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 263,264 bytes 64 bytes (64 aligned) 263,384 bytes 80 bytes (80 aligned)
Guava 263,216 bytes 48 bytes (48 aligned) 263,480 bytes 64 bytes (64 aligned)

Weak Keys & Weak Values

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 263,312 bytes 80 bytes (80 aligned) 263,432 bytes 112 bytes (112 aligned)
Guava 263,392 bytes 40 bytes (40 aligned) 263,584 bytes 72 bytes (72 aligned)

Weak Keys & Soft Values

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 263,312 bytes 88 bytes (88 aligned) 263,432 bytes 120 bytes (120 aligned)
Guava 263,392 bytes 48 bytes (48 aligned) 263,656 bytes 80 bytes (80 aligned)

Soft Values

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 263,264 bytes 72 bytes (72 aligned) 263,384 bytes 88 bytes (88 aligned)
Guava 263,216 bytes 56 bytes (56 aligned) 263,480 bytes 72 bytes (72 aligned)

Clone this wiki locally