modifyIORef lazy? (was Re: BLACKHOLE in heap profile)

Hal Daume III hdaume@ISI.EDU
Fri, 18 Apr 2003 15:38:09 -0700 (PDT)

The code that I was profiling that exhibited this behavior basically
looked like:

  do t <- read a file
     r <- create an io ref
     mapM_ (\c -> do
           modifyIORef r <E>
           ) t

but when i replace:

  modifyIORef r <E>


  v <- readIORef r
  writeIORef r $! <E>

I no longer run into this heap problem and the program runs much more

even if I use (modifyIORef f (\x -> id $! <E> x)), which I thought would
fix it, there is still a heap problem.

looking in the ghc sources, modifyIORef is defined as:

  modifyIORef ref f = writeIORef ref . f =<< readIORef ref

so i don't understand what's going on here.

 Hal Daume III                                   |
 "Arrest this man, he talks in maths."           |

On Fri, 18 Apr 2003, Hal Daume III wrote:

> My program which should use constant stack/heap is using a ton of heap.  I
> profiled with -hd and the guy that's eating all the heap is
> BLACKHOLE.  What does this mean?
> --
>  Hal Daume III                                   |
>  "Arrest this man, he talks in maths."           |