4 ms·
Put and lookup are much slower vs ju.HashMap. For most use cases where the system is already multithreaded the parallel collections don't gain us anything. If
by trailfox 13y ago
Put and lookup are much slower vs ju.HashMap. For most use cases where the system is already multithreaded the parallel collections don't gain us anything.
If you have a large read-only map being read by multiple threads (doing random lookups) ju.HashMap leaves both mutable.Map and immutable.Map very far behind. Scala is great, but the Map performance lags.
I'm not the only one who has noticed. Try googling "Scala map performance vs Java"
- psuter 13y agoFor some use cases (not necessarily yours), it's worth looking at Scala's concurrent.TrieMap.
- orp 13y agoYou should take a look at scala's OpenHashMap - a mutable hashmap in the scala standard library that is often as fast as ju.HashMap. Link to scala doc: http://www.scala-lang.org/api/current/index.html#scala.collection.mutable.OpenHashMap http://www.scala-lang.org/api/current/index.html#scala.colle...
- trailfox 13y agoI have used OpenHashMap, but the results are mixed sometimes is much faster, other times it's much slower. It really depends on the use case.
- bad_user 13y agojava.util.HashMap is not thread-safe, so using it in the context of multiple threads reading from it is less than ideal. The great thing about Scala's immutable HashMap is that in terms of concurrency it is worry-free. You couple it with an AtomicReference and presto, you've got a non-blocking, concurrent HashMap. I work on a really high-volume web service that's built on top of Scala. The performance of Scala's immutable collections has been the least of my worries.
- trailfox 13y agoScala's immutable hashmap is about 4-5x slower than ju.HashMap for reads and 6-7x slower for inserts.