summaryrefslogtreecommitdiff
path: root/Logs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-06-11 16:25:37 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-06-11 16:34:35 -0400
commitd00807c002eecf53efd1967416341a0bbf7ed2d3 (patch)
tree5875dd0081487bb951b02281151677843135338e /Logs
parent671f5025df40937429a6ee85b54d7b3e70ca55f1 (diff)
4 ns optimisation of repeated calls to hasDifference on the same Differences
I want this as fast as possible, so it can be added to code paths without slowing them down. Avoid the set lookup, and rely on laziness, drops runtime from 14.37 ns to 11.03 ns according to this criterion benchmark: import Criterion.Main import qualified Types.Difference as New import qualified Types.DifferenceOld as Old main :: IO () main = defaultMain [ bgroup "hasDifference" [ bench "new" $ whnf (New.hasDifference New.OneLevelObjectHash) new , bench "old" $ whnf (Old.hasDifference Old.OneLevelObjectHash) old ] ] where s = "fromList [ObjectHashLower, OneLevelObjectHash, OneLevelBranchHash]" new = New.readDifferences s old = Old.readDifferences s A little bit of added boilerplate, but I suppose it's worth it to not need to worry about set lookup overhead. Note that adding more differences would slow down the old implementation; the new implementation will run the same speed.
Diffstat (limited to 'Logs')
-rw-r--r--Logs/Difference.hs4
1 files changed, 2 insertions, 2 deletions
diff --git a/Logs/Difference.hs b/Logs/Difference.hs
index 8d37a09c4..fd93fc3cf 100644
--- a/Logs/Difference.hs
+++ b/Logs/Difference.hs
@@ -23,10 +23,10 @@ import Logs.UUIDBased
import Logs.Difference.Pure
recordDifferences :: Differences -> UUID -> Annex ()
-recordDifferences (Differences differences) uuid = do
+recordDifferences ds@(Differences {}) uuid = do
ts <- liftIO getPOSIXTime
Annex.Branch.change differenceLog $
- showLog id . changeLog ts uuid (show differences) . parseLog Just
+ showLog id . changeLog ts uuid (showDifferences ds) . parseLog Just
recordDifferences UnknownDifferences _ = return ()
-- Map of UUIDs that have Differences recorded.