[GHC] #10992: Performance regression due to lack of inlining of `foldl` and `foldl'`. (was: Performance regression)

GHC ghc-devs at haskell.org
Tue Oct 20 12:08:06 UTC 2015


#10992: Performance regression due to lack of inlining of `foldl` and `foldl'`.
---------------------------------+--------------------------------------
        Reporter:  aleator       |                Owner:
            Type:  bug           |               Status:  new
        Priority:  normal        |            Milestone:
       Component:  Compiler      |              Version:  7.10.2
      Resolution:                |             Keywords:  performane
Operating System:  Linux         |         Architecture:  x86_64 (amd64)
 Type of failure:  None/Unknown  |            Test Case:
      Blocked By:                |             Blocking:
 Related Tickets:                |  Differential Rev(s):
       Wiki Page:                |
---------------------------------+--------------------------------------

Comment (by nomeata):

 I looked into this, and the cause is clear: In 7.10, `foldl (+) 0` (which
 is how `GHC.List.sum` is defined) resp. `foldl' (+) 0` are not inlined
 here. If they were, GHC would be able to transform both to the ideal code
 corresponding to an explicit recursion with accumulator.

 If I use these definitions:
 {{{
 sum0 xs = sum xs
 sum3 xs = foldl' (+) 0 xs
 sum5 xs = foldl (+) 0 xs
 }}}
 then I get good code in all cases.

 The reason is that `foldl` is set up so that it inlines once the third
 argument is present:
 {{{
 {-# INLINE foldl #-}
 foldl k z0 xs = ...

 {-# INLINE foldl' #-}
 foldl' k z0 xs =
 }}}
 This makes sense when trying to achieve list fusion, but even with two
 arguments (or maybe even one), inlining would be useful for the strictness
 analyzer to fire.

 I’m however not sure how relevant unsaturated calls to `foldl` are in
 practice.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10992#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list