[Haskell-cafe] Efficient mutable arrays in STM

Ketil Malde ketil at malde.org
Tue Oct 25 22:24:38 CEST 2011

Ben Franksen <ben.franksen at online.de> writes:

> An array of TVars is certainly *much* too inefficient for what I have in 
> mind w.r.t. both memory and cpu time. 

You must be a lot more confident than I if you say this without
benchmarking first. :-) IME, there are (at least) two possible problems
here, 1) transactions scale (quadratically, I think) with the number of
TVars touched, so if any transaction touch a large part of the array,
it's going to cost you, and 2) every element of your array will have a
pointer to it, making GC potentially expensive.  Perhaps you can get
around the latter by tuning GC, e.g. +RTS -A100M might help.

> Or should I use a high-level approach, something like a Data.Sequence.Seq of 
> medium sized chunks (TVar (IOVector e))?

I'm not sure exactly what you mean here, but if you're going to touch
contigous segments of the array, why not TArray (Vector e) or similar?

If I haven't seen further, it is by standing in the footprints of giants

More information about the Haskell-Cafe mailing list