Skip to content

Instantly share code, notes, and snippets.

@tommyettinger
Created June 15, 2019 23:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommyettinger/3f2ff1919500a2b4f6e9e70637119891 to your computer and use it in GitHub Desktop.
Save tommyettinger/3f2ff1919500a2b4f6e9e70637119891 to your computer and use it in GitHub Desktop.
Memory usage of data structures on the JVM
This includes JDK8 and Guava 28 data structures, with the analysis done by https://github.com/DimitrisAndreou/memory-measurer .
========================================== 64-bit architecture ==========================================
========================================== Basic Lists, Sets, Maps ==========================================
ArrayList :: Bytes = 4.71, Objects = 0.00 Refs = 1.18 Primitives = {}
ImmutableList :: Bytes = 4.00, Objects = 0.00 Refs = 1.00 Primitives = {}
HashSet :: Bytes = 40.24, Objects = 1.00 Refs = 5.06 Primitives = {int=1.0}
ImmutableSet :: Bytes = 12.24, Objects = 0.00 Refs = 3.06 Primitives = {}
TreeSet :: Bytes = 40.00, Objects = 1.00 Refs = 5.00 Primitives = {boolean=1.0}
HashMap :: Bytes = 40.24, Objects = 1.00 Refs = 5.06 Primitives = {int=1.0}
ImmutableMap :: Bytes = 32.12, Objects = 1.00 Refs = 4.39 Primitives = {}
LinkedHashMap :: Bytes = 48.24, Objects = 1.00 Refs = 7.06 Primitives = {int=1.0}
TreeMap :: Bytes = 40.00, Objects = 1.00 Refs = 5.00 Primitives = {boolean=1.0}
ImmutableSortedMap :: Bytes = 8.00, Objects = 0.00 Refs = 2.00 Primitives = {}
========================================== Multisets ==========================================
HashMultiset_Worst :: Bytes = 56.24, Objects = 2.00 Refs = 5.06 Primitives = {int=2.0}
LinkedHashMultiset_Worst :: Bytes = 64.24, Objects = 2.00 Refs = 7.06 Primitives = {int=2.0}
TreeMultiset_Worst :: Bytes = 56.00, Objects = 1.00 Refs = 5.00 Primitives = {int=3.0, long=1.0}
ConcurrentHashMultiset_Worst :: Bytes = 56.24, Objects = 2.00 Refs = 5.06 Primitives = {int=2.0}
HashMultiset_Best :: Bytes = 0.00, Objects = 0.00 Refs = 0.00 Primitives = {}
LinkedHashMultiset_Best :: Bytes = 0.00, Objects = 0.00 Refs = 0.00 Primitives = {}
TreeMultiset_Best :: Bytes = 0.00, Objects = 0.00 Refs = 0.00 Primitives = {}
ConcurrentHashMultiset_Best :: Bytes = 0.00, Objects = 0.00 Refs = 0.00 Primitives = {}
========================================== Multimaps ==========================================
HashMultimap_Worst :: Bytes = 168.24, Objects = 5.00 Refs = 17.06 Primitives = {float=1.0, int=5.0}
LinkedHashMultimap_Worst :: Bytes = 160.24, Objects = 4.00 Refs = 21.06 Primitives = {int=4.0}
TreeMultimap_Worst :: Bytes = 144.00, Objects = 4.00 Refs = 18.00 Primitives = {boolean=2.0, int=2.0}
ArrayListMultimap_Worst :: Bytes = 96.24, Objects = 3.00 Refs = 9.06 Primitives = {int=3.0}
LinkedListMultimap_Worst :: Bytes = 104.24, Objects = 3.00 Refs = 13.06 Primitives = {int=2.0}
ImmutableMultimap_Worst :: Bytes = 48.12, Objects = 2.00 Refs = 5.39 Primitives = {}
ImmutableListMultimap_Worst :: Bytes = 48.12, Objects = 2.00 Refs = 5.38 Primitives = {}
ImmutableSetMultimap_Worst :: Bytes = 56.12, Objects = 2.00 Refs = 6.39 Primitives = {int=1.0}
HashMultimap_Best :: Bytes = 40.24, Objects = 1.00 Refs = 5.06 Primitives = {int=1.0}
LinkedHashMultimap_Best :: Bytes = 52.12, Objects = 1.00 Refs = 8.03 Primitives = {int=1.0}
TreeMultimap_Best :: Bytes = 40.00, Objects = 1.00 Refs = 5.00 Primitives = {boolean=1.0}
ArrayListMultimap_Best :: Bytes = 4.07, Objects = 0.00 Refs = 1.02 Primitives = {}
LinkedListMultimap_Best :: Bytes = 40.00, Objects = 1.00 Refs = 6.00 Primitives = {}
ImmutableMultimap_Best :: Bytes = 4.00, Objects = 0.00 Refs = 1.00 Primitives = {}
ImmutableListMultimap_Best :: Bytes = 4.00, Objects = 0.00 Refs = 1.00 Primitives = {}
ImmutableSetMultimap_Best :: Bytes = 12.24, Objects = 0.00 Refs = 3.06 Primitives = {}
========================================== Tables ==========================================
HashBasedTable :: Bytes = 168.24, Objects = 4.00 Refs = 20.06 Primitives = {boolean=1.0, float=1.0, int=5.0}
TreeBasedTable :: Bytes = 128.00, Objects = 3.00 Refs = 17.00 Primitives = {boolean=2.0, int=2.0}
========================================== BiMaps ==========================================
HashBiMap :: Bytes = 56.24, Objects = 1.00 Refs = 8.06 Primitives = {int=2.0}
ImmutableBiMap :: Bytes = 40.77, Objects = 1.00 Refs = 6.19 Primitives = {}
========================================== Misc ==========================================
WeakHashMap :: Bytes = 48.24, Objects = 1.00 Refs = 8.06 Primitives = {int=1.0}
LinkedList :: Bytes = 24.00, Objects = 1.00 Refs = 3.00 Primitives = {}
ArrayDeque :: Bytes = 4.11, Objects = 0.00 Refs = 1.03 Primitives = {}
LinkedHashSet :: Bytes = 48.24, Objects = 1.00 Refs = 7.06 Primitives = {int=1.0}
PriorityQueue :: Bytes = 4.41, Objects = 0.00 Refs = 1.10 Primitives = {}
PriorityBlockingQueue :: Bytes = 4.41, Objects = 0.00 Refs = 1.10 Primitives = {}
ConcurrentSkipListSet :: Bytes = 35.79, Objects = 1.49 Refs = 4.47 Primitives = {int=0.0012600806451612903}
CopyOnWriteArrayList :: Bytes = 4.00, Objects = 0.00 Refs = 1.00 Primitives = {}
CopyOnWriteArraySet :: Bytes = 4.00, Objects = 0.00 Refs = 1.00 Primitives = {}
DelayQueue :: Bytes = 4.41, Objects = 0.00 Refs = 1.10 Primitives = {}
LinkedBlockingQueue :: Bytes = 24.00, Objects = 1.00 Refs = 2.00 Primitives = {}
LinkedBlockingDeque :: Bytes = 24.00, Objects = 1.00 Refs = 3.00 Primitives = {}
========================================== Synchronization Structures ==========================================
ReentrantLock :: Bytes = 48, Objects = 2 Refs = 4 Primitives = [int]
Semaphore :: Bytes = 48, Objects = 2 Refs = 4 Primitives = [int]
ReadWriteLock :: Bytes = 120, Objects = 5 Refs = 11 Primitives = [int x 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment