[GHC] #8766: length [Integer] is twice as slow but length [Int] is 10 times faster

GHC ghc-devs at haskell.org
Tue Feb 11 10:47:35 UTC 2014


#8766: length [Integer] is twice as slow but length [Int] is 10 times faster
--------------------------------------------+------------------------------
        Reporter:  George                   |            Owner:
            Type:  bug                      |           Status:  new
        Priority:  normal                   |        Milestone:
       Component:  Compiler                 |          Version:  7.8.1-rc1
      Resolution:                           |         Keywords:
Operating System:  Unknown/Multiple         |     Architecture:
 Type of failure:  Runtime performance bug  |  Unknown/Multiple
       Test Case:                           |       Difficulty:  Unknown
        Blocking:                           |       Blocked By:
                                            |  Related Tickets:
--------------------------------------------+------------------------------

Comment (by hvr):

 ...here's what simplified Core of

 {{{#!hs
 intlen :: Int
 intlen = length [1..(2^(30::Int))::Int]
 }}}

 looks like for GHC 7.6.3:
 {{{
 intlen =
   case $wf 2 30 of ww { __DEFAULT ->
   case $wlen (eftInt 1 ww) 0 of ww1 { __DEFAULT -> I# ww1 }
   }
 }}}

 vs. GHC 7.8.20140130:
 {{{
 intlen =
   case $wf 2 30 of ww4 { __DEFAULT ->
   case tagToEnum# (># 1 ww4) of _ {
     False ->
       letrec {
         $wgo
         $wgo =
           \ w w1 ->
             case tagToEnum# (==# w ww4) of _ {
               False -> $wgo (+# w 1) (+# w1 1);
               True -> +# w1 1
             }; } in
       case $wgo 1 0 of ww { __DEFAULT -> I# ww };
     True -> I# 0
   }
   }
 }}}

 So the significant runtime reduction for the `Int`-case is seemingly due
 to proper inlining of `eftInt` and thus turning a `length [a..b]` into a
 tighter counting-loop w/o any `[Int]` involved anymore.

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


More information about the ghc-tickets mailing list