[Haskell-cafe] does the compiler optimize repeated calls?
Donald Bruce Stewart
dons at cse.unsw.edu.au
Wed Sep 6 10:06:19 EDT 2006
tpapp:
> Hi,
>
> I have a question about coding and compilers. Suppose that a function
> is invoked with the same parameters inside another function declaration, eg
>
> -- this example does nothing particularly meaningless
> g a b c = let something1 = f a b
> something2 = externalsomething (f a b) 42
> something3 = externalsomething2 (137 * (f a b)) in
> ...
>
> Does it help (performancewise) to have
>
> g a b c = let resultoff = f a b
> something2 = externalsomething resultoff 42
> something3 = externalsomething2 (137 * resultoff) in
> ...
>
> or does the compiler perform this optimization? More generally, if a
> function is invoked with the same parameters again (and it doesn't
> involve anything like monads), does does it makes sense
> (performancewise) to "store" the result somewhere?
>
on the wiki,
http://www.haskell.org/haskellwiki/Performance/GHC#Common_subexpressions
-- Don
More information about the Haskell-Cafe
mailing list