Has there been any work on supporting vector-style recycling for general data in Haskell? For example running
main = do
let ls = [1..1000000]
print ls
with -p
states that it allocates a total of 425mb. Running
main = do
let ls = [1..1000000]
print ls
print (ls ++ [1])
with -p
states that it allocates ~twice that, at 820mb.
I understand why this is happening, but I'm wondering why GHC does not perform this optimization. I suppose one reason is that it doesn't show up much in real code so the benefits are slight, if anything (but maybe a general way to recycle any inductive structure could give some benefit?). Usually people are told to use other data structures anyways (e.g. Data.Seq).
ps - I've seen links to the 'Recycle Your Arrays!' paper by Roman Leshchinskiy, however all links on the web are now dead (and I don't want to pay to read it via Springer)
edit:
When I use deepseq instead of print, I get similar but less extreme results. Without the append I get 80mb and with the append is 136mb. Not as extreme but it's still a bit of memory that, in theory, could be saved.