The Spark

The other day I came across a fascinating post on Substack by Skilled Coder about Java data structure performance. The post showed some eye-opening numbers for 10M operations:

Get operations:

  • HashMap.get() → ~140 ms
  • TreeMap.get() → ~420 ms
  • ArrayList.get(i) → ~40 ms
  • LinkedList.get(i) → ~2.5 s

Insertion (10M elements):

  • ArrayList.add() → ~180 ms
  • HashMap.put() → ~300 ms
  • LinkedList.add() → ~900 ms

This got me thinking: how do these numbers compare to Eclipse Collections? And more importantly, how can we calculate these numbers ourselves using open source tools?

Why Eclipse Collections?

Eclipse Collections (EC) has an interesting history. It started around 2004 (probably for Java 1.4) because of buggy and slow implementations in the JDK at the time. Goldman Sachs originally developed it as GS Collections before donating it to the Eclipse Foundation.

Today, EC provides drop-in replacements for JDK collections with additional functionality and, as we’ll see, slightly better performance.

The Benchmark Setup

I used JMH (Java Microbenchmark Harness) to run proper benchmarks. You can see the full results on my Java Benchmarks page.

Quick Comparison

Get (avg per operation):

OperationTime
ArrayList.get()~0.833 ns
HashMap.get()~4.324 ns
TreeMap.get()~272.823 ns
LinkedList.get()~6,036,876.394 ns

Insertion (avg per operation):

OperationTime
ArrayList.add()~133.370 ns
HashMap.put()~378.101 ns
TreeMap.put()~432.432 ns
LinkedList.add()~408.091 ns

Detailed Comparison: JDK vs Eclipse Collections

StructureTypeInsertion (ns/op)Get (ns/op)
ArrayListJDK~133.370 ns~0.833 ns
MutableList (FastList)EC~129.426 ns~0.831 ns
HashMapJDK~378.101 ns~4.324 ns
MutableMap (UnifiedMap)EC~371.230 ns~3.796 ns
TreeMapJDK~432.432 ns~272.823 ns
TreeSortedMapEC~480.139 ns~271.022 ns
LinkedListJDK~408.091 ns~6,036,876.394 ns

Key Takeaways

1. Eclipse Collections is slightly faster overall

For the most commonly used collections (List and Map), EC shows consistent improvements:

  • FastList beats ArrayList by ~3% on insertion and is essentially equal on get
  • UnifiedMap beats HashMap by ~2% on insertion and ~12% on get

2. TreeMap vs TreeSortedMap is a wash

TreeSortedMap is slightly slower on insertion (~11%) but marginally faster on get. If you need sorted maps, either choice works well.

3. LinkedList is still terrible for random access

Look at that LinkedList.get() number: ~6 million nanoseconds per operation! This is because LinkedList has O(n) complexity for random access — it must traverse the list from the beginning (or end) to find each element.

As Skilled Coder wisely noted: “Once you know this, you stop misusing LinkedList forever.”

Why These Performance Differences?

Understanding the “why” helps you make better choices:

  • ArrayList/FastList = contiguous memory, cache-friendly. The CPU can prefetch data efficiently.
  • HashMap/UnifiedMap = hashing + pointer chasing. UnifiedMap uses a more compact memory layout.
  • TreeMap/TreeSortedMap = O(log n) + rebalancing. Red-black tree operations.
  • LinkedList = worst cache locality + pointer traversal. Every access is a cache miss.

When to Use Eclipse Collections

Consider EC when:

  • You’re doing heavy collection operations and every nanosecond counts
  • You want additional APIs like select(), reject(), collect(), groupBy()
  • You need primitive collections (avoiding boxing overhead)
  • You want immutable collections with a rich API

Running Your Own Benchmarks

Want to reproduce these results? Check out the JMH documentation and my benchmark code at java-benchmarks.

Wrap-up

This was a fun research project! The numbers confirm what the Eclipse Collections team has been saying for years: their implementations are well-optimized and can provide meaningful performance improvements over JDK collections.

For most applications, the difference won’t be noticeable. But if you’re building high-performance systems or processing large datasets, EC is worth considering.

I shared these findings on my Substack — feel free to check it out and share your own benchmark experiences!

References