-
Notifications
You must be signed in to change notification settings - Fork 141
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
Provide unconsN/unsnocN? #524
Comments
I'll see if I can provide a minimal benchmark for this. The filepath function using those, went from:
to:
|
So:
Implementation of |
I think it would be good to figure out the performance problem with |
In particular I wonder whether the actual performance problem might lie with your use of |
See the PR. It's not about |
I don't think so, because |
The current implementation is: unpackBytes :: ShortByteString -> [Word8]
unpackBytes sbs = unpackAppendBytesLazy sbs []
unpackAppendBytesLazy :: ShortByteString -> [Word8] -> [Word8]
unpackAppendBytesLazy sbs = go 0 (length sbs)
where
sz = 100
go off len ws
| len <= sz = unpackAppendBytesStrict sbs off len ws
| otherwise = unpackAppendBytesStrict sbs off sz remainder
where remainder = go (off+sz) (len-sz) ws
unpackAppendBytesStrict :: ShortByteString -> Int -> Int -> [Word8] -> [Word8]
unpackAppendBytesStrict !sbs off len = go (off-1) (off-1 + len)
where
go !sentinal !i !acc
| i == sentinal = acc
| otherwise = let !w = indexWord8Array (asBA sbs) i
in go sentinal (i-1) (w:acc) which I don't understand at all... in fact. I changed it to unpackBytes :: ShortByteString -> [Word8]
unpackBytes sbs = let ix = length sbs - 1
in List.map (unsafeIndex sbs) [0..ix] and that seemed to speed it up considerably:
but I'm not sure if there's different memory behavior and if that does something to inlining and list fusion. |
In an attempt to improve performance of filepath functions using ShortByteString I figured that
unpack
slowed down a couple of functions. Moving to several calls of uncons seemed to improve performance. In particular:https://gitlab.haskell.org/haskell/filepath/-/merge_requests/116/diffs
The 3 consecutive calls to uncons are not only awkward, but also incur 3 copies for the tail.
So I'm wondering if a function like this might be useful (at least for
ShortByteString
):The obvious disadvantage here is that you'll get partial pattern matching on the Word list, because we don't have dependent types.
Providing
uncons2
,uncons3
and using a tuple instead might be an alternative, but less general.The other way would be to figure out why unpack is so slow. Afaiu it's only semi lazy, e.g. unpacks the first 100 bytes strictly.
The text was updated successfully, but these errors were encountered: