[Haskell-cafe] Re: does the compiler optimize repeated calls?

Sebastian Sylvan sylvan at student.chalmers.se
Wed Sep 6 09:12:28 EDT 2006

On 9/6/06, Alex Queiroz <asandroq at gmail.com> wrote:
> Hallo,
> On 9/6/06, Lennart Augustsson <lennart at augustsson.net> wrote:
> > Furthermore, doing that optimization (common subexpression
> > elimination) can lead to space leaks.  So you should not count on the
> > compiler doing it.  Besides, I often find it more readable and less
> > error prone to name a common subexpression; only one place to change
> > when you need to change the call.
> >
>      So there is no benefits from the "functions have no side-effects"
> property, performance-wise. Pity.

I think most compilers actually do CSE (to varying extents), but it's
not a good idea to rely on it since nobody will ever *guarantee* that
it's done.

Purely functional does give you some performance benefits, though.
Such as getting pass-by-reference performance "for free" (i.e. without
actually having to worry about pass-by-reference semantics -- send a
huge data structure "by value" to a function and it will really only
be a pointer that gets sent). You can also do parallel and other
multithreading stuff much easier which should surely count as a major
performance benefit.

Sebastian Sylvan
UIN: 44640862

More information about the Haskell-Cafe mailing list