-
Notifications
You must be signed in to change notification settings - Fork 139
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
dropWhile is slow #141
Comments
This was commented a bit in #108. |
The `unstream` version results in a copy of the remainder of the vector which is rarely what you want to do. This commit uses `drop` directly after `findIndex` which results in a big speed gain if the remaining part of the vector is large. Cf. haskell#108 and haskell#141
So, I feel like this is an example of a broader problem. In your example, you will have a big vector materialized in memory. Streaming this to drop some elements and then making a new vector is a lot of work compared to changing the offset/length and reusing the underlying array. However, another use case of vector is stream fusion, and if stream fusion is happening, this new implementation (in pull request #146) actually breaks it up in sub-optimal ways. And it's kind of accidental that However, I think that maybe the generalized stream fusion can do something better than it is doing right now. I think this was the point of the generalized fusion, so I don't really understand why it wasn't used here, or in lots of other places ( |
Yeah, sharing vs slicing is a tricky trade off ! |
I see. So ideally we would have Thanks for the insight by the way. Up to this point I did not understand what Bundle does -- apparently it is for exactly this purpose of choosing whether to stream or slice? |
That's sort of the idea, yes. A simpler example than bundle is that you can use the type: data CoYo f a = forall e. CY (e -> a) (f e) to fuse up data BundleYo f a = forall e. BY (e -> a) (f e) (f a) Where the extra The only tricky part I can think of is that the selection of algorithms kind of flows one way in bundles. So, I think |
For this matter, why don't we just have dropWhile f (new (New.unstream s)) = new (New.unstream (Bundle.dropWhile f s)) I'm soon gonna submit a pull request for this. |
Sounds wonderful!
…On Fri, Jun 5, 2020 at 12:05 PM Genki Sato ***@***.***> wrote:
For this matter, why don't we just have dropWhile be like current
implementation index or head or tail ? That is, we could define dropWhile
f = snd . span f with INLINE_FUSED and have a rule
dropWhile f (unstream s) = unstream (Bundle.dropWhile f s)
I'm soon gonna submit a pull request for this.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#141 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAABBQSXVIWTV2R7BHMW67DRVEJVVANCNFSM4CTQSUWQ>
.
|
Now dropWhile's implementation uses stream only in case the stream fusion is already running. This is expected to reduce unnecessary re-allocation. cf. haskell#141 haskell#108
I've submitted a pull request for this, finally! #327 |
* make dropWhile fusion adaptive Now dropWhile's implementation uses stream only in case the stream fusion is already running. This is expected to reduce unnecessary re-allocation. cf. #141 #108 * Adaptive dropWhile Implementation: Implementation comment modified Modified the comment for the RULE "dropWhile/unstream [Vector]" in order to make the intention of the implementation there clear.
Fixed by #327 |
* make dropWhile fusion adaptive Now dropWhile's implementation uses stream only in case the stream fusion is already running. This is expected to reduce unnecessary re-allocation. cf. #141 #108 * Adaptive dropWhile Implementation: Implementation comment modified Modified the comment for the RULE "dropWhile/unstream [Vector]" in order to make the intention of the implementation there clear.
the following example shows
dropWhile
being roughly 60x slower thanfindIndex
followed bydrop n
with-O3
-- and roughly 560x slower without-O3
!https://github.com/charles-cooper/vector-perf
The text was updated successfully, but these errors were encountered: