Performance: Faster to define a function writing out all arguments?

Simon Peyton-Jones simonpj at microsoft.com
Tue May 13 04:47:47 EDT 2008


| > Anyway, as I am still wondering why ghc creates different code for
| >   returnP a = return a
| >   returnP = return
| >
|
| Ah, now I rember this coming up before.
|
| Simon, is this a CAF issue? Or did it trigger the -fno-state-hack case?

I'm not sure.  A small example would be good.

| I've definitely run into the odd other case where point-freeing
| a bit of code messes with the complexity.

That should not happen -- except for the state-hack. Which is this:

Consider
        f1 :: Char -> IO ()
        f1 = \c. let i = ord c in \s. print i s

Here s::State World.  Is this equivalent to
        f2 = \c.\s. print (ord c) s

The latter is very much more efficient than 'f1', because it doesn't build an intermediate lambda.  This matters a lot in I/O-intensive programs.   But if 'f' is called thus:

        forever (f 'w')

then (ord 'w') is computed once for each call of f2, but is shared among all calls to f1.  And that can make a big difference too.


I have no idea whether this is playing a role in the example you are discussing -- my guess is not, and there may be another performance bug lurking. So eliciting a small demo would be great.

Simon



More information about the Glasgow-haskell-users mailing list