max-key or min-key will evaluate (k value) multiple times for arguments if more than 2 arguments are passed. This is undesirable if k is expensive to calculate.
Good perf test:
Approach: Avoid repeated evaluation of k for any element.
A criterium test of the example above shows:
Before: 206.017411 µs
After: 126.532306 µs
Patch: clj-99-v3.patch
Comment made by: stevemkim
sort-by is similarly inefficient. It calls keyfn for every comparison in sort, not once for every element to be sorted.
I'm not familiar with this project's preferred workflow, so I have to ask: Do you want me to open a separate ticket for sort-by, or do you prefer to consolidate that issue into this ticket?
Separate.
Comment made by: stevemkim
I created [CLJ-1402] for sort-by
clj-99-v2 applies cleanly to master
clj-99-v3.patch behaves correctly for collection elements that are nil or false.