In Java, according to the usage of a collection, we do not use the same implementation (ie ArrayList vs LinkedList).
Coming from a Java background, can someone tell me what should I know about Scala collections and performance considerations?
It seems the immutable version of Scala List is some kind of immutable LinkedList. I understand the concepts, following Martin Odersky courses on Coursera. In the same way i understand why it's more efficient to prepend than to append, particularly when you have an immutable list.
I would like to know all (or most) of these kind of tricky things about Scala collection performances, so that I do not find it myself the hard way. Can someone help me?
Thanks
Scala vs Java performance Some coders claim that Scala is a little bit faster than Java programming with 20% fast processing. Optimization in Scala language makes code compilation much faster than Java coding.
Combine Scala and Java seamlessly Similarly, Java code can reference Scala classes and objects. In this example, the Scala class Author implements the Java interface Comparable<T> and works with Java File s. The Java code uses a method from the companion object Author , and accesses fields of the Author class.
A java list can be returned from a Scala program by writing a user defined method of Java in Scala. Here, we don't even need to import any Scala's JavaConversions object in order to make this conversions work.
A collection in package scala. collection can be either mutable or immutable.
There's a document that describes collection performance characteristics. Beyond that, you really should test your use case in a microbenchmark. In some cases, Scala collections are very close in performance to Java ones; in others there's a gap (e.g. maps); in others there is no Java analog and the immutable vs. mutable comparison depends very highly on how you use the collection (with, obviously, heavy mutation favoring mutable collections, and heavy re-use/copying favoring immutable collections).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With