-O causing a 7x slowdown (Map of IORef's)
Simon Marlow
simonmar at microsoft.com
Mon Apr 25 06:40:57 EDT 2005
On 23 April 2005 16:06, Remi Turk wrote:
> the attached program is about 7 times slower when compiled
> _with_ -O using ghc 6.4. Using ghc 6.2.1 with ddata's Map gives
> the same behaviour.
My analysis of this: the problem is the get function:
get mc k= readIORef (mc ! k)
in the unoptimised version, the (mc ! k) is only computed once, as it
should be. The optimised version has eta-expanded this function so that
(mc ! k) is evaluated once per iteration.
This is because of a mis-optimisation by GHC - we try a bit too hard to
optimise IO monad code, sacrificing a little performance-safety in the
process.
You can turn off this particular (mis-)feature with -fno-state-hack, in
which case the program goes about 5 times faster.
We'll take a look and see if the IO monad optimisation can be made any
safer.
Cheers,
Simon
More information about the Glasgow-haskell-bugs
mailing list