Skip to content

Memory explodes trying to consume chunked pure stream #115

@qrpnxz

Description

@qrpnxz

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:

  1. Removing bang from Step (unless there's a good reason for it to have a bang).
  2. Adding a non-strict Step constructor
  3. Adding a lazy version of S.each (by adding Effects to it like repeats, or better using another constructor)
  4. Adding a note about this problem, and how to get around it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions