summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Feuer <David.Feuer@gmail.com>2014-10-27 10:21:20 +0100
committerHerbert Valerio Riedel <hvr@gnu.org>2014-10-27 10:24:21 +0100
commit9e2cb00e5af9d86546f82a74c3d0382e65704d56 (patch)
tree7546b6c0ee63094b9239c2722e1df03ede2f4fe5
parent0a290ca0ad599e40ca15a60cc988640f1cfcb4c2 (diff)
downloadhaskell-9e2cb00e5af9d86546f82a74c3d0382e65704d56.tar.gz
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: https://phabricator.haskell.org/D315
-rw-r--r--libraries/base/Data/IORef.hs6
1 files changed, 3 insertions, 3 deletions
diff --git a/libraries/base/Data/IORef.hs b/libraries/base/Data/IORef.hs
index 0e5717cb7c..2981805cb6 100644
--- a/libraries/base/Data/IORef.hs
+++ b/libraries/base/Data/IORef.hs
@@ -106,9 +106,9 @@ atomicModifyIORef = GHC.IORef.atomicModifyIORef
-- /Since: 4.6.0.0/
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