[GHC] #11701: ghc generates significant slower code

GHC ghc-devs at haskell.org
Fri Mar 11 23:18:33 UTC 2016


#11701: ghc generates significant slower code
-------------------------------------+-------------------------------------
           Reporter:  HuStmpHrrr     |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  7.10.3
           Keywords:  efficiency     |  Operating System:  Linux
       Architecture:  x86_64         |   Type of failure:  Runtime
  (amd64)                            |  performance bug
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 I've already started a discussion here in SO:
 http://stackoverflow.com/questions/35941674/latest-ghc-generates-slower-
 code

 So again, I realized that the latest version of ghc produces significantly
 slower code than older version. my default ghc is the latest version as of
 now:

 {{{
 $ ghc --version
 The Glorious Glasgow Haskell Compilation System, version 7.10.3
 }}}

 I have also two other old versions installed in my local machine.

 test code as following

 {{{#!hs
 import Data.Word
 import Data.List
 import System.Environment

 collatzNext :: Word32 -> Word32
 collatzNext a = (if even a then a else 3*a+1) `div` 2

 -- new code
 collatzLen :: Word32 -> Int
 collatzLen a0 = lenIterWhile collatzNext (/= 1) a0

 lenIterWhile :: (a -> a) -> (a -> Bool) -> a -> Int
 lenIterWhile next notDone start = len start 0 where
     len n m = if notDone n
                 then len (next n) (m+1)
                 else m
 -- End of new code

 main = do
     [a0] <- getArgs
     let max_a0 = (read a0)::Word32
     print $ maximum $ map (\a0 -> (collatzLen a0, a0)) [1..max_a0]
 }}}

 following are the three runs in my machine:

 {{{
 $ ~/Tools/ghc-7.6.1/bin/ghc -O2 Test.hs
 [1 of 1] Compiling Main             ( Test.hs, Test.o )
 Linking Test ...

 $ time ./Test 1000000
 (329,837799)

 real    0m1.901s
 user    0m1.896s
 sys     0m0.000s

 $ ~/Tools/ghc/bin/ghc -O2 Test.hs
 [1 of 1] Compiling Main             ( Test.hs, Test.o )
 Linking Test ...

 $ time ./Test 1000000
 (329,837799)

 real    0m10.562s
 user    0m10.528s
 sys     0m0.036s

 $ ~/Tools/ghc-7.4.2/bin/ghc -O2 Test.hs
 [1 of 1] Compiling Main             ( Test.hs, Test.o )
 Linking Test ...

 $ time ./Test 1000000
 (329,837799)

 real    0m1.879s
 user    0m1.876s
 sys     0m0.000s
 }}}

 Obviously we can tell latest version of ghc produces worse code than the
 older two versions.

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


More information about the ghc-tickets mailing list