Unwanted eta-expansion
Roman Cheplyaka
roma at ro-che.info
Sun Oct 9 16:54:18 CEST 2011
* Jan-Willem Maessen <jmaessen at alum.mit.edu> [2011-10-08 12:32:18-0400]
> It seems to be a common misconception that eta-abstracting your
> functions in this way will speed up or otherwise improve your code.
>
> Simon PJ has already provided a good explanation of why GHC eta
> expands. Let me take another tack and describe why the code you wrote
> without eta expansion probably doesn't provide you with any actual
> benefit. Roughly speaking, you're creating a chain of closures whose
> contents exactly describe the contents of your list (ie you've created
> something that's isomorphic to your original list structure), and so
> you should expect no benefit at all.
Thanks for the analysis.
I used myFoldl as a minimal example to ask the question.
Here's an example of real code where this does make a difference:
https://github.com/feuerbach/regex-applicative/tree/03ca9c852f06bf9a9d51505640b8b72f07291c7d
You can run the benchmark (on a POSIX system) using
cd benchmark && ./runbenchmark.sh
With the current version I get 2.62 seconds.
If I remove -fno-do-lambda-eta-expansion for
Text/Regex/Applicative/Compile.hs, the benchmark takes 2.74 seconds.
What's even more interesting (and puzzling!), if remove
-fno-do-lambda-eta-expansion for Text/Regex/Applicative/Types.hs,
the benchmark takes 2.82 seconds.
I appreciate any thoughts about this.
--
Roman I. Cheplyaka :: http://ro-che.info/
More information about the Glasgow-haskell-users
mailing list