Comparing three approaches to filtering a list of 1 million already sorted elements.
The filter predicate matches after 10 elements, i.e. relatively early.
via filter: expected to be slow because all elements have to be traversed
list.filter(predicate)
via skipUntil: expected to be fast
list.skipUntil(predicate)
via findIndex/takeLast: expected to be fast (similar to skipUntil)
From @netzwerg on Tue, 05 May 2020 08:16:17 GMT
What happened
Comparing three approaches to filtering a list of 1 million already sorted elements. The filter predicate matches after 10 elements, i.e. relatively early.
via
filter
: expected to be slow because all elements have to be traversedlist.filter(predicate)
via
skipUntil
: expected to be fastlist.skipUntil(predicate)
via
findIndex/takeLast
: expected to be fast (similar toskipUntil
)list.takeLast(list.size - list.findIndex(predicate))
Performance of
3.8.2
is according to expectations:Performance of
4.0.0-rc.12
differs from expectations,skipUntil
is very slow, indicating a potential regression:How to reproduce
https://github.com/netzwerg/immutable-js-perf
Copied from original issue: https://github.com/immutable-js/immutable-js/issues/1770