Is there somewhere I can find out the expected time and space complexities of operations on collections like HashSet, TreeSet, List and so on?
Is one just expected to know these from the properties of the abstract-data-types themselves?
I know of Performance characteristics for Scala collections, but this only mentions some very basic operations. Perhaps the rest of the operations for these collections are built purely from a small base-set, but then, it seems I am just expected to know that they have implemented them in this way?
Performance characteristics of the other methods is really difficult to assert. Consider the following:
foreachoriterator, and at usually very high levels in the hierachy.Vector‘smapis implemented oncollection.TraversableLike, for example.To add insult to injury, which method implementation is used depends on the linearization of the class inheritance. This also applies to any method called as a helper. It has happened before that changes here caused unforeseen performance problems.
Since
foreachanditeratorare bothO(n), any improved performance depends on specialization at other methods, such assizeandslice.So the result is that the place where the method is defined — and documented — does not have near enough information to state its performance characteristics, and may depend not only on how other methods are implemented by the inheriting collection, but even by the performance characteristics of an object, Builder, obtained from CanBuildFrom, that is passed at the call site.
At best, any such documentation would be described in terms of other methods. Which doesn’t mean it isn’t worthwhile, but it isn’t easily done — and hard tasks on open source projects depend on volunteers, who usually work at what they like, not what is needed.