logo       

RE: -O causing a 7x slowdown (Map of IORef's): msg#00118

lang.haskell.glasgow.bugs

Subject: RE: -O causing a 7x slowdown (Map of IORef's)

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


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise