-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Memory overhead zh CN
Ben Manes edited this page Aug 31, 2025
·
5 revisions
MemoryBenchmark的估算基于Java Agent for Memory Measurements和Java Object Layout计算运行时大小。该大小可能受JVM确定的压缩引用、对象填充等因素影响。
通过分叉Java 5的ConcurrentHashMap,Guava凭借逐条目优化略占优势。当使用弱引用和软引用缓存时,这种优势尤为显著。由于装饰了Java 8的ConcurrentHashMap,Caffeine必须保留额外字段才能移除被回收的条目。
Caffeine可能根据使用情况延迟初始化或动态调整其内部数据结构的大小。这减少了内存占用,仅在满足使用需求(如吞吐量)时才分配额外内存。
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |

