Skip to content

Memory overhead

Ben Manes edited this page Apr 8, 2016 · 18 revisions

Estimates were performed using Java Agent for Memory Measurements to calculate the runtime size. The size may be affected by compressed references, object padding, etc. applied by the JVM. This benchmark may be run using gradle memoryOverhead which executes the MemoryBenchmark.

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 Entry
Caffeine 264 bytes 54 bytes (56 aligned)
Guava 1,032 bytes 58 bytes (64 aligned)

Maximum Size

Cache Baseline Entry
Caffeine 1,112 bytes 74 bytes (80 aligned)
Guava 1,384 bytes 74 bytes (80 aligned)

Maximum Size & Expire after Access

Cache Baseline Entry
Caffeine 1,152 bytes 82 bytes (88 aligned)
Guava 1,384 bytes 74 bytes (80 aligned)

Maximum Size & Expire after Write

Cache Baseline Entry
Caffeine 1,176 bytes 90 bytes (96 aligned)
Guava 1,544 bytes 90 bytes (96 aligned)

Maximum Size & Refresh after Write

Cache Baseline Entry
Caffeine 1,168 bytes 90 bytes (96 aligned)
Guava 27,200 bytes (?) 90 bytes (96 aligned)

Maximum Weight

Cache Baseline Entry
Caffeine 1,120 bytes 82 bytes (88 aligned)
Guava 1,376 bytes 74 bytes (80 aligned)

Expire after Access

Cache Baseline Entry
Caffeine 1,008 bytes 82 bytes (88 aligned)
Guava 1,384 bytes 74 bytes (80 aligned)

Expire after Write

Cache Baseline Entry
Caffeine 1,008 bytes 82 bytes (88 aligned)
Guava 1,192 bytes 74 bytes (80 aligned)

Expire after Access & after Write

Cache Baseline Entry
Caffeine 1,048 bytes 98 bytes (104 aligned)
Guava 1,544 bytes 90 bytes (96 aligned)

Weak Keys

Cache Baseline Entry
Caffeine 560 bytes 98 bytes (104 aligned)
Guava 1,240 bytes 66 bytes (72 aligned)

Weak Values

Cache Baseline Entry
Caffeine 560 bytes 98 bytes (104 aligned)
Guava 1,240 bytes 74 bytes (80 aligned)

Weak Keys & Weak Values

Cache Baseline Entry
Caffeine 616 bytes 130 bytes (136 aligned)
Guava 1,416 bytes 82 bytes (88 aligned)

Weak Keys & Soft Values

Cache Baseline Entry
Caffeine 616 bytes 146 bytes (152 aligned)
Guava 1,416 bytes 98 bytes (104 aligned)

Soft Values

Cache Baseline Entry
Caffeine 560 bytes 114 bytes (120 aligned)
Guava 1,240 bytes 90 bytes (96 aligned)