
#8972: Investigate adding fast compare-and-swap Int type/primops -------------------------------------+------------------------------------ Reporter: tibbe | Owner: tibbe Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.9 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by tibbe): I've added a little benchmark that shows that even calling out to C can speed things up a lot. Using `IORef`: {{{ $ ghc -O2 Bench.hs counter.c -DOLD=1 ... $ time ./Bench real 0m1.698s user 0m1.670s sys 0m0.020s }}} Calling out to C: {{{ $ ghc -O2 Bench.hs counter.c ... $ time ./Bench real 0m0.108s user 0m0.090s sys 0m0.010s }}} That's a ~16x speed-up. Things look similar with the threaded RTS: Using `IORef`: {{{ $ ghc -O2 Bench.hs counter.c -DOLD=1 -threaded ... $ time ./Bench real 0m1.998s user 0m1.980s sys 0m0.010s }}} Calling out to C: {{{ $ ghc -O2 Bench.hs counter.c -threaded $ time ./Bench real 0m0.117s user 0m0.100s sys 0m0.010s }}} With `+RTS -N6` (real hardware cores on the test machine): Using `IORef`: {{{ $ time ./Bench +RTS -N6 real 1m22.565s user 1m23.850s sys 1m11.240s }}} Calling out to C: {{{ $ time ./Bench +RTS -N6 real 0m0.247s user 0m1.340s sys 0m0.010s }}} Atrocious results for the `IORef` solution! It seems like contended `IORef`s don't work well at all. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8972#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler