-
Notifications
You must be signed in to change notification settings - Fork 67
Linear getByteString
#76
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
Conversation
bea0981
to
b6cf044
Compare
Note that this is probably better done with a |
b6cf044
to
bf8eb3e
Compare
Chains of `B.append`s were being created by repeated calls to `demandInput`. Try the following program, which writes and read 100MB, to appreciate the difference: ``` import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as BSL import Data.Binary (encode, decode) import Data.Char (ord) main :: IO () main = do let inBs = BS.replicate 100000000 (fromIntegral $ ord 'a') BSL.writeFile "bs.bin" (encode inBs) putStrLn "writing done" bin <- BSL.readFile "bs.bin" -- This takes around 30 seconds and causes more than 10GB to be -- allocated. let outBs = decode bin print $ inBs == outBs ```
bf8eb3e
to
e46b7b6
Compare
Hey! Thanks for the fix. Indeed, there's a problem with I'm not sure why a |
Wasn't the previous |
Part of it was inlineable. That part is used whenever there is enough input (99% of the time). |
...by making the common case (when the input is big enough) non-recursive.
I pushed a commit that makes |
Thanks! I'll have a look later today. |
Quoting the changelog, this pulls in the following fixes: binary-0.7.5.0 -------------- - Fix performance bug that was noticable when you get a big strict ByteString and the input to the decoder consists of many small chunks. - haskell/binary#73 - haskell/binary#76 - Fix memory leak when decoding Double and Float. - Commit 497a181c083fa9faf7fa3aa64d1d8deb9ac76ecb - We now require QuickCheck >= 2.8. Remove our version of arbitrarySizedNatural. binary-0.7.4.0 -------------- - Some invalid UTF-8 strings caused an exception when decoded. Those errors will now now fail in the Get monad instead. See issue 70. Patch contributed by @ttuegel.
Quoting the changelog, this pulls in the following fixes: binary-0.7.5.0 -------------- - Fix performance bug that was noticable when you get a big strict ByteString and the input to the decoder consists of many small chunks. - haskell/binary#73 - haskell/binary#76 - Fix memory leak when decoding Double and Float. - Commit 497a181c083fa9faf7fa3aa64d1d8deb9ac76ecb - We now require QuickCheck >= 2.8. Remove our version of arbitrarySizedNatural. binary-0.7.4.0 -------------- - Some invalid UTF-8 strings caused an exception when decoded. Those errors will now now fail in the Get monad instead. See issue 70. Patch contributed by @ttuegel. (cherry picked from commit 7dd0ea7)
getByteString
exhibited quadratic behaviour -- a classic case of bad "appending". This commit fixes it.