[Haskell-cafe] more sharing in generated code

Joachim Breitner mail at joachim-breitner.de
Sun Nov 4 13:00:40 CET 2012


Hi,

Am Samstag, den 03.11.2012, 11:26 +0100 schrieb Peter Divianszky:
> > This can be implemented by replacing every record update
> >
> >     r' = r { x = y }
> >
> > with
> >
> >     r' = r { x = unsafePerformIO (cond-update r r' (x r) y) }
> >
> > where we keep the current record update mechanism and implement
> > cond-update like
> >
>
> cond-update :: r -> r -> x -> IO x
> cond-update r_old r_new x_old x_new = do
>       eval x_new
>       b <- x_old === x_new
>       when b (replace r_new r_old)
>       return x_new
> 
> > where (===) is pointer-equality and replace is a low-level function
> > which replaces thunks in the heap.

I think one problem with this approach is that now, until "x r'" is
evaluated, you keep both r and r' alive. If r was _not_ retained by
anything else, then you are now preventing the GC from freeing it and
hence increasing the memory footprint.

Greetings,
Joachim


-- 
Joachim "nomeata" Breitner
  mail at joachim-breitner.de  |  nomeata at debian.org  |  GPG: 0x4743206C
  xmpp: nomeata at joachim-breitner.de | http://www.joachim-breitner.de/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121104/fc33f70b/attachment.pgp>


More information about the Haskell-Cafe mailing list