[GHC] #11365: Worse performance with -O

GHC ghc-devs at haskell.org
Wed Jan 6 22:29:47 UTC 2016


#11365: Worse performance with -O
-------------------------------------+-------------------------------------
           Reporter:                 |             Owner:
  facundo.dominguez                  |
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:
           Keywords:  optimization   |  Operating System:  Unknown/Multiple
  performance concurrency            |
       Architecture:                 |   Type of failure:  Runtime
  Unknown/Multiple                   |  performance bug
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 The running time of the following program worsens when compiled with
 {{{-O}}}, and worsens more when compiled with ghc-7.10.2.

 {{{
 #!haskell
 -- /opt/ghc-7.8.3/bin/ghc --make -threaded -fforce-recomp test.hs
 -- time ./test: 3 seconds
 --
 -- /opt/ghc-7.8.3/bin/ghc --make -threaded -O -fforce-recomp test.hs
 -- time ./test: 11 seconds
 --
 -- /opt/ghc-7.10.2/bin/ghc --make -threaded -fforce-recomp test.hs
 -- time ./test: 5 seconds
 --
 -- /opt/ghc-7.10.2/bin/ghc --make -threaded -O -fforce-recomp test.hs
 -- time ./test: 13 seconds
 --

 import Control.Concurrent
 import Control.Monad
 import Data.List

 main :: IO ()
 main = do
   let x = foldl' (+) 0 [1 .. 100000000]
   mv <- newEmptyMVar
   replicateM_ 4 $ forkIO $ putMVar mv $! x
   nums <- replicateM 4 $ takeMVar mv
   print (nums :: [Integer])
 }}}

 The following variant which doesn't share {{{x}}} improves with {{{-O}}}
 for ghc-7.10.2, but ghc-7.8.3 still produces a faster program.

 {{{
 #!haskell
 -- /opt/ghc-7.8.3/bin/ghc --make -threaded -fforce-recomp test.hs
 -- time ./test: 10 seconds
 --
 -- /opt/ghc-7.8.3/bin/ghc --make -threaded -O -fforce-recomp test.hs
 -- time ./test: 11 seconds
 --
 -- /opt/ghc-7.10.2/bin/ghc --make -threaded -fforce-recomp test.hs
 -- time ./test: 18 seconds
 --
 -- /opt/ghc-7.10.2/bin/ghc --make -threaded -O -fforce-recomp test.hs
 -- time ./test: 15 seconds
 --

 import Control.Concurrent
 import Control.Monad
 import Data.IORef
 import Data.List

 main :: IO ()
 main = do
   mv <- newEmptyMVar
   ref <- newIORef 0
   replicateM_ 4 $ forkIO $ do
     i <- readIORef ref
     putMVar mv $! foldl' (+) i [1 .. 100000000]
   nums <- replicateM 4 $ takeMVar mv
   print (nums :: [Integer])
 }}}

 Some related discussion [https://mail.haskell.org/pipermail/ghc-
 devs/2016-January/010904.html here].

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


More information about the ghc-tickets mailing list