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 128 bytes 32 bytes (32 aligned) 200 bytes 32 bytes (32 aligned)
Guava 928 bytes 48 bytes (48 aligned) 1,120 bytes 48 bytes (48 aligned)

Maximum Size

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

Maximum Size & Expire after Access

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

Maximum Size & Expire after Write

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

Maximum Size & Refresh after Write

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

Maximum Weight

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

Expire after Access

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

Expire after Write

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

Expire after Access & after Write

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

Weak Keys

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

Weak Values

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

Weak Keys & Weak Values

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

Weak Keys & Soft Values

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

Soft Values

Cache Baseline (MemoryMeter) Per Entry (MemoryMeter) Baseline (ObjectLayout) Per Entry (ObjectLayout)
Caffeine 1,136 bytes 88 bytes (88 aligned) 1,208 bytes 88 bytes (88 aligned)
Guava 1,136 bytes 72 bytes (72 aligned) 1,400 bytes 72 bytes (72 aligned)

Clone this wiki locally