I was trying to use mapsM and chunksOf to go from Stream (Of Word8) to Stream (Of ByteString), and found that consuming even just 200MB was allocating dozens of Gigabytes memory. Discovered that the problem was eagerness. My infinite source (Of Word8) was a series of Steps, which are strict on the Functor (why?). If I use repeats to construct the Stream, then the code behaves sanely again, albeit taking twice as long as using splitsAt by hand since, to add laziness, repeats interleaves pure Effects into the stream. (Which S.each does not do.)
Things to consider:
- Removing bang from
Step (unless there's a good reason for it to have a bang).
- Adding a non-strict
Step constructor
- Adding a lazy version of
S.each (by adding Effects to it like repeats, or better using another constructor)
- Adding a note about this problem, and how to get around it.
I was trying to use
mapsMandchunksOfto go fromStream (Of Word8)toStream (Of ByteString), and found that consuming even just 200MB was allocating dozens of Gigabytes memory. Discovered that the problem was eagerness. My infinite source(Of Word8)was a series ofSteps, which are strict on theFunctor(why?). If I userepeatsto construct theStream, then the code behaves sanely again, albeit taking twice as long as usingsplitsAtby hand since, to add laziness,repeatsinterleaves pureEffects into the stream. (WhichS.eachdoes not do.)Things to consider:
Step(unless there's a good reason for it to have a bang).StepconstructorS.each(by addingEffects to it likerepeats, or better using another constructor)