summaryrefslogtreecommitdiff
path: root/Types/Distribution.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2019-11-22 16:24:04 -0400
committerJoey Hess <joeyh@joeyh.name>2019-11-22 17:49:16 -0400
commit81d402216d955260fd4744ab73031b4c693d6254 (patch)
treeca1f150a09fbf46f1966f760e4854cf3da587acc /Types/Distribution.hs
parente296637737eb409fd55b5fb1b09c959a793b0d09 (diff)
cache the serialization of a Key
This will speed up the common case where a Key is deserialized from disk, but is then serialized to build eg, the path to the annex object. Previously attempted in 4536c93bb2ecf114ab711beac33fa358facd6985 and reverted in 96aba8eff7597898f53bfbab5865ff30a927d355. The problems mentioned in the latter commit are addressed now: Read/Show of KeyData is backwards-compatible with Read/Show of Key from before this change, so Types.Distribution will keep working. The Eq instance is fixed. Also, Key has smart constructors, avoiding needing to remember to update the cached serialization. Used git-annex benchmark: find is 7% faster whereis is 3% faster get when all files are already present is 5% faster Generally, the benchmarks are running 0.1 seconds faster per 2000 files, on a ram disk in my laptop.
Diffstat (limited to 'Types/Distribution.hs')
-rw-r--r--Types/Distribution.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/Types/Distribution.hs b/Types/Distribution.hs
index b41a90a1c0..c0ad2c02fd 100644
--- a/Types/Distribution.hs
+++ b/Types/Distribution.hs
@@ -21,7 +21,9 @@ type GitAnnexVersion = String
data GitAnnexDistribution = GitAnnexDistribution
{ distributionUrl :: String
- , distributionKey :: Key
+ , distributionKey :: KeyData
+ -- ^ This used to be a Key, but now KeyData serializes
+ -- to Key { ... }, so back-compat for Read and Show is preserved.
, distributionVersion :: GitAnnexVersion
, distributionReleasedate :: UTCTime
, distributionUrgentUpgrade :: Maybe GitAnnexVersion
@@ -46,7 +48,7 @@ parseInfoFile s = case lines s of
formatGitAnnexDistribution :: GitAnnexDistribution -> String
formatGitAnnexDistribution d = unlines
[ distributionUrl d
- , serializeKey (distributionKey d)
+ , serializeKey $ mkKey $ const $ distributionKey d
, distributionVersion d
, show (distributionReleasedate d)
, maybe "" show (distributionUrgentUpgrade d)
@@ -56,7 +58,7 @@ parseGitAnnexDistribution :: String -> Maybe GitAnnexDistribution
parseGitAnnexDistribution s = case lines s of
(u:k:v:d:uu:_) -> GitAnnexDistribution
<$> pure u
- <*> deserializeKey k
+ <*> fmap (fromKey id) (deserializeKey k)
<*> pure v
<*> readish d
<*> pure (readish uu)