<div dir="ltr">Hello,<div>I tried to load a ~50MB csv file in memory with cassava but found that my program was incredibly slow. After doing some profiling, I realized that it used an enormous amount of memory in the heap:</div><div><br></div><div>24,626,540,552 bytes allocated in the heap</div><div>6,946,460,688 bytes copied during GC</div><div>2,000,644,712 bytes copied maximum residency (14 sample(s))</div><div>319,728,944 bytes maximum slop</div><div>3718 MB total memory in use (0MB lost due to fragmentation)</div><div>...</div><div>%GC time 84.0% (94.3% elapsed)</div><div><br></div><div>Seeing that, I have the feeling that my program lacks strictness and accumulates thunks in memory. I tried two versions, on using Data.Csv, and one using Data.Csv.Streaming. Both are giving the same result. What am I doing wrong?</div><div><br></div><div>Here are the two sources:</div><div>1/</div><div>import Data.Csv</div><div>import Data.ByteString.Lazy as BL</div><div>import qualified Data.Vector as V</div><div><br></div><div>main :: IO ()</div><div>main = do</div><div>   csv <- BL.readFile "tt.csv"</div><div>   let !res = case decode NoHeader csv of Right q -> q :: V.Vector(V.Vector(ByteString))</div><div>   print $ res V.! 0</div><div><br></div><div><br></div><div>--------------------------------</div><div>2/</div><div>import Data.Csv.Streaming</div><div>import Data.ByteString.Lazy as BL</div><div>import qualified Data.Vector as V</div><div>import Data.Foldable</div><div><br></div><div>main :: IO ()</div><div>main = do</div><div>   csv <- BL.readFile "tt.csv"</div><div>   let !a = decode NoHeader csv :: Records(V.Vector(ByteString))</div><div>   let !xx = V.fromList $ [V.fromList([])] :: V.Vector(V.Vector(ByteString))</div><div>   let !res = Data.Foldable.foldr' V.cons xx a</div><div>   print $ res V.! 0</div><div><br></div><div><br></div><div>The goal of the program is ultimately to have the csv loaded in memory as a Vector of Vector of ByteString for further processing later on.</div><div><br></div><div><br></div><div>Thank you for your help,</div><div><br></div><div>Antoine</div></div>