Open benjaminp opened 5 years ago
I agree list.sort
can be useful in a few cases.
In my experience, it's rare though. Converting a depset to a sorted list shouldn't be frequent (flattening a depset should be avoided when possible).
Moving to bazelbuild/starlark as it's a FR for a method on a universe symbol (list).
Also, does it make sense to talk about minimizing the number of copies if you're doing a non-in-place sort anyway? sorted()
is implemented using Java's Arrays.sort()
, which itself in the worst case behaves as merge sort (which typically is not implemented as an in-place sort).
Or to put it another way: If merge sort requires O(log n) copies, it shouldn't matter too much if we're doing O(log n) + 1 copies. Is any performance improvement demonstrable in this case?
The mutating
list.sort
method is occasionally useful for efficiency reasons.In particular, under
--incompatible_depset_is_not_iterable
, there doesn't seem to be any way to go from a nested set to a sorted collection with less than 2 copies. One must writesorted(a_depset.to_list())
.