build/fold causes with ByteString unpack causes huge memory leak
module Main where
import qualified Data.ByteString as B import Data.Word (Word8)
-- works fast without optimizations -- with optimizations this has a space leak -- seems related to fold/build fusion in foldr/unpack
main :: IO () main = do
let b = B.replicate 100000000 1 print $ B.length b print $ example1 b -- fast print $ example2 b -- slow
search :: [Word8] -> Bool search [] = False search (x:xs) = x == 1 || search xs
example1, example2 :: B.ByteString -> Bool example1 = search . B.unpack example2 = foldr (\x xs -> x == 1 || xs) False . B.unpack
Trac metadata
Trac field | Value |
---|---|
Version | 7.6.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries/base |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |