[Haskell-cafe] Fusion for fun and profi (Was: newbie optimization question)

Tim Chevalier catamorphism at gmail.com
Sun Oct 28 17:02:21 EDT 2007


On 10/28/07, Stefan O'Rear <stefanor at cox.net> wrote:
> On Sun, Oct 28, 2007 at 01:43:07PM -0700, Don Stewart wrote:
> > stefanor:
> > > IO blocks unboxing in GHC.  How fast is your mock-C code refactored to
> > > do IO outside of the loops only?
> >
> > It doesn't! The above code yields:
> >
> >     Main.$wloop :: GHC.Prim.Int#
> >                    -> GHC.Prim.State# GHC.Prim.RealWorld
> >                    -> (# GHC.Prim.State# GHC.Prim.RealWorld, () #)
> >
> >     $wgo_rMK :: GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int#
> >         where
> >             $s$wgo_rMI :: GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int#
>
> Ah, interesting.  I was reading something too general from
> http://hackage.haskell.org/trac/ghc/ticket/1592#comment:5.
>

Right, unboxing is successful here because the arguments are marked as
strict with (!) annotations. The IO hack described in that bug report
would only be a problem if the arguments were not marked strict, and
were used in code that has to be executed after an IO call.

Although I don't think all of the strictness annotations are even
necessary here.  In any case, loop must evaluate i before the call to
print; there would only be an issue if it called an IO function before
doing anything that demands i.

Cheers,
Tim

-- 
Tim Chevalier * catamorphism.org * Often in error, never in doubt
"Accordingly, computer scientists commonly choose models which have
bottoms, but prefer them topless." -- Davey & Priestley, _Introduction
to Lattices and Order_


More information about the Haskell-Cafe mailing list