Display warning about copy for lazy ByteString more prominent
I had a huge memory-leak in my application because when reading the documentation for BSL.ByteString suggests that copy should allow the "parent" to be released for GC. I thought this was a bit suspicious, but went with it anyways and it turned out quite bad... So I checked the source:
-- | /O(n)/ Make a copy of the 'ByteString' with its own storage.
-- This is mainly useful to allow the rest of the data pointed
-- to by the 'ByteString' to be garbage collected, for example
-- if a large string has been read in, and only a small part of it
-- is needed in the rest of the program.
copy :: ByteString -> ByteString
copy cs = foldrChunks (Chunk . S.copy) Empty cs
--TODO, we could coalese small blocks here
--FIXME: probably not strict enough, if we're doing this to avoid retaining
-- the parent blocks then we'd better copy strictly.
Important part here is the FIXME which does not show up in the docs but is critical in my opinion. Can we move this there?
I'm happy to have us document the fact that it still works lazily, ie chunks are copied as the result is demanded, and to note that in some use cases it may thus be necessary to force the whole result to ensure the copies are made. I don't think changing it to include a force is a good idea though, it would make it unusable in pipelines.