You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make `zipWith` build its result with the structure of its first
argument, splitting up its second argument as it goes. This allows
fast random access to the elements of the results immediately,
without having to build large portions of the structure. It also
seems to be slightly faster than the old implementation when the
entire result is used, presumably by avoiding rebalancing costs.
I believe most of this code will also help implement a fast
`(<*>)`.
Use the same approach to implement `zipWith3` and `zipWith4`.
Clean up a couple warnings.
Many thanks to Carter Schonwald for suggesting that I use the
structure of the first sequence to structure the result, and for
helping me come up with the splitTraverse approach.
Benchmarks:
Zipping two 100000 element lists and extracting the 50000th element
takes about 11.4ms with the new implementation, as opposed to 88ms with
the old. Zipping two 10000 element sequences and forcing the result to
normal form takes 4.0ms now rather than 19.7ms. The indexing gains show
up for even very short sequences, but the new implementation really
starts to look good once the size gets to around 1000--presumably it
handles cache effects better than the old one. Note that the naive
approach of converting sequences to lists, zipping them, and then
converting back, actually works very well for forcing short sequences to
normal form, even better than the new implementation. But it starts to
lose a lot of ground by the time the size gets to around 10000, and its
performance on the indexing tests is bad.
splitTraverseTree f s (Deep n pr m sf) =Deep n (splitTraverseDigit f prs pr) (splitTraverseTree (splitTraverseNode f) ms m) (splitTraverseDigit f sfs sf)
0 commit comments