effect of order of function arguments

Josef Svenningsson josefs@cs.chalmers.se
Wed, 19 Feb 2003 15:50:42 +0100 (MET)


[moved over to glasgow-haskell-users]

On Wed, 19 Feb 2003, Simon Peyton-Jones wrote:

> | GHC used to have an optimisation for static argument like this. It
> would
> | turn both of the above programs into a similar form using a local
> | recursive function:
> |
> | interp y xs = interpaux xs
> |   where interpaux [] = []
> | 	interpaux (x:[]) = x:[]
> |         interpaux (x:xs) = x:y:interpaux xs
> |
> | GHC doesn't do this anymore. The reason for this is unknown to me.
>
> It turned out to be a very minor effect (1-2% of execution time) and
> hard to tune; with lots of parameters, it's best to make a local
> function, with just a few it's best to pass the parameters round.
>
I see. I'm a little surprised though. I thought that performing SAT
(static argument transformation) would make GHC much keener on inlining
the function. My expectation was that there would be some gain from that.

Just as a comment I can add that in my paper "Shortcut fusion for
accumulating parameters & zip-like functions" in last year's ICFP I
performed SAT by hand on the definition of unfoldr and foldl' in order to
make all the inlining happen in the way I wanted. Without this I would
either have to rely on the compiler performing SAT or there would be no
fusion.

My gut feeling (which ofcourse can be wrong) is that SAT can play an
important role when transforming programs.

	/Josef