Commit 9e2cb00e authored by David Feuer's avatar David Feuer Committed by Herbert Valerio Riedel

Optimise atomicModifyIORef' implementation (#8345)

This forces the new value before installing it in the IORef.

This optimisation was originally suggested by Patrick Palka
and "exhibits a speedup of 1.7x (vanilla RTS) / 1.4x (threaded RTS)"
according to #8345

Reviewed By: austin, simonmar

Differential Revision:
parent 0a290ca0
......@@ -106,9 +106,9 @@ atomicModifyIORef = GHC.IORef.atomicModifyIORef
-- /Since:
atomicModifyIORef' :: IORef a -> (a -> (a,b)) -> IO b
atomicModifyIORef' ref f = do
b <- atomicModifyIORef ref
(\x -> let (a, b) = f x
in (a, a `seq` b))
b <- atomicModifyIORef ref $ \a ->
case f a of
v@(a',_) -> a' `seq` v
b `seq` return b
-- | Variant of 'writeIORef' with the \"barrier to reordering\" property that
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment