Koloboke Compile

Combine collection features in the most efficient way.

Koloboke Compile is an annotation processor for Java 6+. It generates implementations for Map-like and Set-like abstract classes or interfaces.

Based on the abstract methods and annotations, Koloboke Compile generates the most efficient possible implementation for a particular abstract class or interface.

Koloboke Compile saves you from writing a collection implementation manually (that incurs testing, support and reliability costs), when you need a combination of collection features not available in JDK or “traditional” collection libraries.  For example, with JDK you cannot create a simple, not synchronized hash map, which disallows inserting and querying the null key. You have to write (and test, and support) a decorator class for HashMap.  With Koloboke Compile, you can write just:

abstract class NonnullKeyMap<K, V> implements Map<K, V> {
    static <K, V> Map<K, V> withExpectedSize(int expectedSize) {
        return new KolobokeNonnullKeyMap<K, V>(expectedSize);


Koloboke Compile squeezes the last 5% of speed in critical use cases, compared to the Koloboke implementation library. The only way to compare with Koloboke Compile in speed is to write collection implementations manually. For example, here is how the fastest map for the classic “word count” problem looks like:

abstract class WordCountMap {
    static WordCountMap withExpectedSize(int expectedSize) {
        return new KolobokeWordCountMap(expectedSize);

    abstract int addValue(String key, int addition);
    abstract int getInt(String key);


Other reasons to prefer Koloboke Compile to “traditional” libraries of optimized collections like fastutil, Eclipse, HPPC, Trove, and even the Koloboke implementation library:

  • No API lock-in. As you can notice from the examples above, Koloboke Compile doesn’t bring its own 15th standard of collections interfaces; it implements your abstract classes (or interfaces), or any existing collections API (examples: Koloboke, Trove).
  • Smaller runtime dependencies. To use Koloboke Compile, a project should have two runtime dependencies of total size of about 1 MB. Eclipse Collections library is about 9 MB, fastutil and Koloboke implementation library (+ dependencies) are about 19 MB.In future Koloboke Compile may require zero runtime dependencies (vote for this feature in the survey below).

To start using Koloboke Compile, read the Koloboke Compile tutorial.

Drawbacks of Koloboke Compile

  • It slows down the project build. Each implementation that Koloboke Compile should generate adds about 2-3 seconds to the total build time.
  • Koloboke Compile generates self-contained implementations, they don’t share code. JVM loads more classes.

State of the project

Koloboke Compile is considered stable and production ready.

Currently Koloboke Compile supports the following collection features:

This is only a little fraction of all possible collection features. Koloboke Compile is in the minimum valuable state, not the “final” state. If you want some lacking features to be added sooner, please vote in the following survey: