bazelbuild / starlark

Starlark Language
Apache License 2.0
2.48k stars 163 forks source link

Add list.sort #174

Open benjaminp opened 5 years ago

benjaminp commented 5 years ago

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

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

brandjon commented 3 years ago

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

brandjon commented 3 years ago

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?