[GHC] #11029: Performance loss due to eta expansion
GHC
ghc-devs at haskell.org
Wed Oct 28 11:22:51 UTC 2015
#11029: Performance loss due to eta expansion
-------------------------------------+-------------------------------------
Reporter: NeilMitchell | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Description changed by NeilMitchell:
Old description:
> Given the attached file, at both {{{-O2}}} and {{{-O0}}}, GHC translates
> the function:
>
> {{{#!hs
> test1 [1,2,3,4,5,6,7,8,9,10] = \x -> x
> test1 _ = \x -> negate x
> }}}
>
> To be equivalent to:
>
> {{{#!hs
> test0 [1,2,3,4,5,6,7,8,9,10] x = x
> test0 _ x = negate x
> }}}
>
> When applied in a loop with something like:
>
> {{{#!hs
> map (test1 [1..]) [1..1000]
> }}}
>
> The eta-expanded variant is 3x slower. Adding a trace breaks that
> transformation, and then the code goes 3x faster. Specifically:
>
> {noformat}
> test2 [1,2,3,4,5,6,7,8,9,10] = \x -> x
> test2 _ = trace "here" $ \x -> negate x
> {noformat}
>
> Timings, as reported by Criterion under O2 with GHC 7.10.2, are:
>
> {{{
> benchmarking test0 = 40.99 ns (40.96 ns .. 41.02 ns)
> benchmarking test1 = 41.09 ns (41.06 ns .. 41.14 ns)
> benchmarking test2 = 17.74 ns (17.68 ns .. 17.81 ns)
> }}}
New description:
Given the attached file, at both {{{-O2}}} and {{{-O0}}}, GHC translates
the function:
{{{#!hs
test1 [1,2,3,4,5,6,7,8,9,10] = \x -> x
test1 _ = \x -> negate x
}}}
To be equivalent to:
{{{#!hs
test0 [1,2,3,4,5,6,7,8,9,10] x = x
test0 _ x = negate x
}}}
When applied in a loop with something like:
{{{#!hs
map (test1 [1..]) [1..1000]
}}}
The eta-expanded variant is 3x slower. Adding a trace breaks that
transformation, and then the code goes 3x faster. Specifically:
{{{#!hs
test2 [1,2,3,4,5,6,7,8,9,10] = \x -> x
test2 _ = trace "here" $ \x -> negate x
}}}
Timings, as reported by Criterion under O2 with GHC 7.10.2, are:
{{{
benchmarking test0 = 40.99 ns (40.96 ns .. 41.02 ns)
benchmarking test1 = 41.09 ns (41.06 ns .. 41.14 ns)
benchmarking test2 = 17.74 ns (17.68 ns .. 17.81 ns)
}}}
--
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11029#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list