Skip to content

conc004.hs mis-optimised (performance weirdness)

The following program
(fptools/testsuite/tests/ghc-regress/concurrent/should_run/conc004.hs)
runs about 10 times as slowly when compiled with -O,
both with 6.2.1 and with todays CVS.

% ghc -no-recomp conc004.hs
% time ./a.out
donereal 1.97
user 1.88
sys 0.05

% ghc -no-recomp -O conc004.hs
% time ./a.out                
donereal 21.69
user 20.40
sys 0.12


Strange enough, profiling completely reverses this:

% ghc -no-recomp -prof -auto-all conc004.hs   
% time ./a.out +RTS -p                     
donereal 20.23
user 17.81
sys 0.18

total time  =        2.10 secs   (105 ticks @ 20 ms)
total alloc = 1,116,017,312 bytes  (excludes profiling
overheads)

versus

% ghc -no-recomp -prof -auto-all -O conc004.hs
% time ./a.out +RTS -p
donereal 1.35
user 1.31
sys 0.01

total time  =        0.94 secs   (47 ticks @ 20 ms)
total alloc = 1,060,017,180 bytes  (excludes profiling
overheads)


Which seems pretty weird. Except that multithreaded
programs are well known for weird (timing) problems ;o)


module Main where

-- Test thread creation.
-- (from: Einar Wolfgang Karlsen
<ewk@Informatik.Uni-Bremen.DE>)

import Control.Concurrent

main :: IO ()
main = do
   mvar <- newEmptyMVar

   let 
   	spawner :: (IO () -> IO ThreadId) -> Int -> IO ()
   	spawner c 0 = putMVar mvar ()
   	spawner c n = do { c (spawner c (n-1)); return ()}

   spawner forkIO 1000000
   takeMVar mvar
   putStr "done"
Trac metadata
Trac field Value
Version 6.2.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution ResolvedFixed
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information