From: Joey Hess Date: Wed, 10 Feb 2021 20:38:33 +0000 (-0400) Subject: optimisation X-Git-Tag: archive/raspbian/10.20250416-2+rpi1~1^2~98^2~19 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=dc9376feebc3108634244ff458ae4cf64e4ffe4b;p=git-annex.git optimisation IORef rather than MVar sped up benchmark mentioned in last commit to 13.0s. This makes me wonder if changing the interface to not need the IORef either would improve speed further. --- diff --git a/Backend/Hash.hs b/Backend/Hash.hs index 0e723dea5d..53ba19c599 100644 --- a/Backend/Hash.hs +++ b/Backend/Hash.hs @@ -28,7 +28,7 @@ import qualified Data.ByteString.Char8 as S8 import qualified Data.ByteString.Lazy as L import Control.DeepSeq import Control.Exception (evaluate) -import Control.Concurrent.MVar +import Data.IORef data Hash = MD5Hash @@ -280,15 +280,11 @@ md5Hasher = mkHasher md5 md5_context mkIncrementalVerifier :: HashAlgorithm h => Context h -> Key -> IO IncrementalVerifier mkIncrementalVerifier ctx key = do - v <- newMVar ctx + v <- newIORef ctx return $ IncrementalVerifier - { updateIncremental = \b -> do - ctx' <- takeMVar v - let ctx'' = hashUpdate ctx' b - evaluate $ rnf ctx'' - putMVar v ctx'' + { updateIncremental = modifyIORef' v . flip hashUpdate , finalizeIncremental = do - ctx' <- takeMVar v + ctx' <- readIORef v let digest = hashFinalize ctx' return $ sameCheckSum key (show digest) }