Got this from filtering a list with multiple filters and I don’t see how it will help performance?
Since I need to go through each item the exact same steps (only in a different order) in the two variants.
But using a sequence I need to first convert it into a sequence. Why is this a performance boost?
The code:
First, toSequence for a collection uses the iterator on the existing collection (IIRC), so no real cost here.
If you leave it as a list, your code will create 5 new lists, one after each filter.
A sequence processes each element through all the steps (or at least until it gets filtered out), so it only creates one list.
That's where the gain can come from.
b
bob
01/08/2020, 1:11 PM
Thank you for that clarification! 🙏
p
Paul Woitaschek
01/08/2020, 1:45 PM
Yet if your features list does not countain a lot of elements there is no performance to gain
Paul Woitaschek
01/08/2020, 1:45 PM
I use sequences only if there is some way of early abort
Paul Woitaschek
01/08/2020, 1:45 PM
like .sequence-filter-filter-filter-first()
b
bob
01/08/2020, 2:13 PM
Yeah, I've got a shortlist of 20 items and just a bunch of filters. And even if I use a sequence, I will perform the same amount of filtering calls.
But now I can make an informed decision if I want to make the switch or not.
So I'll stick with the list for now.