There are often examples of code which sorts by a complex expression. E.g.,
At the moment myPreferredName will be called each time a row is compared. It is often much more efficient to project that computed value into the dataset, and then compare that new field. However there are also cases where it isn't so good:
i) the function creates a large temporary value, which might mean the sort spills much earlier if it is projected out.
ii) The complex function is a trailing component. E.g.,
SORT(ds, a, b, c, something-complex).
That is only more efficient to pre-project if there are likely to be duplicate rows with the same values for fields a,b,c. Otherwise you may end up executing the function more often, and pay the penalty for storing the value as well.