
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