Skip to content

Concurrent Multimaps

PXAV edited this page Mar 18, 2021 · 1 revision

...

Performance

In the background, Kelp's concurrent multimaps use a ConcurrentHashMap to save their values. This is what makes them thread-safe. But this also means that things like values() (a list of all values saved in the multimap) take relatively long to compute as they have to iterate through all entries of the main map and in there again through all collection elements. This makes the ConcurrentMultimap significantly slower in the following operations:

  • values() a list of all values saved in the multimap. Every collection element from the main map is a separate element in this list.
  • entries() a list of all entries saved in the multimap. An entry is defined by a key and a single value. So if a key is assigned multiple values, there will be multiple elements of this key in the final collection.
  • containsEntry() only slightly slower than the normal method. In tests with 25 000 checks it only performed 3-5ms slower than the normal Multimap

It is planned to improve the algorithms for those methods in the future for further performance improvement. But apart from that, the ConcurrentMultimaps have been optimized for the most-used operations on a spigot-server and are faster than a normal Multimap here, which includes:

  • All put() methods (tested with 300 000 bulk inserts)
  • containsKey()
  • containsValue()
  • removeEntry()
  • removeAll(), clear()
Clone this wiki locally