starlark icon indicating copy to clipboard operation
starlark copied to clipboard

Add list.sort

Open benjaminp opened this issue 6 years ago • 3 comments

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 write sorted(a_depset.to_list()).

benjaminp avatar May 20 '19 17:05 benjaminp

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).

laurentlb avatar May 22 '19 21:05 laurentlb

Moving to bazelbuild/starlark as it's a FR for a method on a universe symbol (list).

brandjon avatar Feb 19 '21 04:02 brandjon

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?

brandjon avatar Feb 19 '21 16:02 brandjon