Search code examples
javalatencychroniclechronicle-map

Chronicle map using primitives


In Chronicle-map description it is said:

Chronicle Map provides in-memory access speeds, and supports ultra-low garbage collection. Chronicle Map can support the most demanding of applications.

What does supports ultra-low garbage collection actually stand for? Does it mean that the Chronicle map tries to allocate as few objects as possible in heap?

As far as I know, projects which have low latency requirements try to avoid unnecessary allocations, partly by using gc-free collections, partly by object pooling. One of them is avoiding unnecessary boxing/unboxing of the primitives. For example if you have a Map<Long, Entity>, to avoid creating Long objects, you can use map implementations based on value types, like TLongObjectMap<Value> in trove library.

Then it would make sense to make it possible to create chronicle-map instance in such manner, using primitives as keys, for example. Is it possible? If not, are there any reasons behind not implementing this?


Solution

  • Yes, this is possible to use ChronicleMap without making a single allocation (i. e. garbage) on the hot path. If you have primitive keys (or values), you should use flyweight pattern facilitated by Chronicle Values library. See Value interfaces instead of boxed primitives section in the tutorial.