New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 Really nice change!
@jekyllbot: merge +minor |
Hey!
I was reading through the
Enumerable#sort_by
documentation 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
#sort
by reducing object allocations. I'm in!I tested it on the
_docs
collection in our jekyllrb.com site and it is quite impressive:Based on these numbers, I switched
Jekyll::Filters#sort_input
to use this method.🎉 🐎