Premature Optimization in the implementation of Collectors.toList()
Remi Forax
forax at univ-mlv.fr
Thu May 30 07:57:45 PDT 2013
There current implementation can return three different implementations,
an empty list, a singleton list and an ArrayList.
While trying to minimize the memory consumption may be a good idea,
this will make all codes that use the resulting list (by example in a
for-each-loop)
megamorphic effectively disabling any possible inlining of the iterator
(if we stay with our for-each-loop example).
Given that the Stream API is not used in the wild for now, this
optimization is premature,
because we have no idea if this implementation is better or worst that
the dumb
implementation, the one similar to the one used in toSet().
We should stick with the dumb implementation and try to optimize later,
when we will have enough data about the usage of the resulting list.
Rémi
More information about the lambda-libs-spec-experts
mailing list