A more efficient atomicModifyIORef'
|Reported by:||parcs||Owned by:|
|Type of failure:||Runtime performance bug||Difficulty:||Moderate (less than a day)|
|Test Case:||Blocked By:|
atomicModifyIORef' is currently defined as:
atomicModifyIORef' ref f = do b <- atomicModifyIORef ref (\x -> let (a, b) = f x in (a, a `seq` b)) b `seq` return b
This doesn't seem to be the best we can do, though.
The following implementation exhibits a speedup of 1.7x (vanilla RTS) / 1.4x (threaded RTS) over the current implementation:
atomicModifyIORef' ref f = do b <- atomicModifyIORef ref $ \a -> case f a of v@(a',_) -> a' `seq` v b `seq` return b
The differences between this version and the current version are:
- the lambda is now strict in f a, and
- a new result tuple is no longer being allocated.
Is there a good reason why atomicModifyIORef' is not already defined this way?
Change History (3)
comment:2 Changed 4 days ago by hvr
- Difficulty changed from Unknown to Moderate (less than a day)
- Keywords IORef added
- Milestone set to 7.10.1
- Type changed from task to bug
- Type of failure changed from None/Unknown to Runtime performance bug