Use a Schwartzian transform with custom sorting#6342
Conversation
ccee9be to
dae8e24
Compare
|
nice implementation Parker 👍 I did come across this transformation while reading up for another PR, but never bothered to bench an implementation.. If you have the time can you please benchmark using |
Updated. I had to ensure I was copying the |
WOW!! Très cool!!! |
I don't think we can do that, because each implementation will pull the |
| apple_property <=> orange_property | ||
| input.map { |item| [item_property(item, property), item] } | ||
| .sort! do |apple_info, orange_info| | ||
| apple_property = apple_info.first |
There was a problem hiding this comment.
Based on the benchmark results, Array#[] was faster than Array#first correct? Should we switch to that or did I interpret the benchmark results incorrectly?
|
What happens if we switch to input.sort_by { |item| item_property(item, property) } |
|
@jekyllbot: merge +minor |
Hey!
I was reading through the
Enumerable#sort_bydocumentation and came across an interesting passage about how it gets its speed-up:Whoa! A hidden gem: a recommendation about getting the most out of
#sortby reducing object allocations. I'm in!I tested it on the
_docscollection in our jekyllrb.com site and it is quite impressive:Based on these numbers, I switched
Jekyll::Filters#sort_inputto use this method.🎉 🐎