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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add find filters to optimize where-first chains #8171
Conversation
What's the expected gain? If liquid don't have it, why should we? |
As of now, there is no
For the general user-base? Depends on how it is used. |
I've added a benchmark script to compare the performance of the |
@DirtyF Liquid has a different implementation of |
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.
According to the profile docs tests, this brings a significant improvement for build time 馃憤
@jekyll: merge +minor |
Summary
Introducing Liquid filters
find
andfind_exp
to optimize scenarios involvingfirst
chained towhere
andwhere_exp
filter respectively.Purpose
where
(where_exp
) evaluates given conditions against all items in a given array and chaining thefirst
filter returns a single object from the pool. This could be wasteful when the array is large with numerous items and the first winner is near the starting end.i.e. say the array is
["apple", "lemonade", "spade", "sunglasses", "umbrella", "cola"]
{{ array | where: "type", "drink" | first }}
and{{ array | find: "type", "drink" }}
are equivalent and return the same object ("lemonade"
) but the latter stops processing after two items.