[Haskell-cafe] ST Vector / STRef -- Performances and allocation

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Sun Jun 19 13:44:07 UTC 2016


Bertram Felgenhauer via Haskell-Cafe wrote:
> Guillaume Bouchard wrote:
> > - PRef (Unboxed bytearray of size 1, the closest thing to an unboxed
> > stack allocation) : 86ms
> > - URef (Unboxed vector of size 1) : 130ms
> > - SRef (Storable vector of size 1) : 43ms (This is an improvement !)
> > - BRef (Boxed ref) : 137ms
> > - STRef : 54ms (this was my baseline)
> 
> You really shouldn't use any mutable variable at all for this, but pass
> the values around as function arguments instead [...]

As to why, the reason is that to get good performance, these variables
should end up in registers. But the mutable variables in Haskell are
all heap-allocated objects, and afaik the compiler has no way of
allocating them elsewhere (on the stack, or in a register). So the only
way to get good code is to not use Haskell's mutable variables at all.

All this is specific to ghc, obviously.

Cheers,

Bertram



More information about the Haskell-Cafe mailing list