summaryrefslogtreecommitdiff
path: root/Annex.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-09-29 13:36:48 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-09-29 13:36:48 -0400
commit4d6f7038b86ebb6c583b8881c2ff47722a32f95f (patch)
tree83f03fb833cbca661c25364ee224c0f6204a1f3d /Annex.hs
parent6cc0c44b26197439d35f3f53c8621f7f113841ab (diff)
Optimisations to git-annex branch query and setting, avoiding repeated copies of the environment.
Speeds up commands like "git-annex find --in remote" by over 50%. Profiling showed that adjustGitEnv was 21% of the time and 37% of the allocations of that command. It copied the environment each time with getEnvironment. The only repeated use of adjustGitEnv is in withIndexFile, which tends to be run at least once per file. So, it was optimised by keeping a cache of the environment, which can be reused. There could be other better ways to optimise this. Maybe get the while environment once at startup. But, then it would have to be serialized back out each time running a child process, so I doubt that would be a net win. It might be better to cache a version of the environment that is pre-modified to use .git-annex/index. But, profiling doesn't show that modifying the enviroment is taking any significant time.
Diffstat (limited to 'Annex.hs')
-rw-r--r--Annex.hs6
1 files changed, 4 insertions, 2 deletions
diff --git a/Annex.hs b/Annex.hs
index 8f46f112c..1ee6e837f 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -139,6 +139,7 @@ data AnnexState = AnnexState
, activeremotes :: MVar (S.Set (Types.Remote.RemoteA Annex))
, keysdbhandle :: Maybe Keys.DbHandle
, cachedcurrentbranch :: Maybe Git.Branch
+ , cachedgitenv :: Maybe [(String, String)]
}
newState :: GitConfig -> Git.Repo -> IO AnnexState
@@ -189,6 +190,7 @@ newState c r = do
, activeremotes = emptyactiveremotes
, keysdbhandle = Nothing
, cachedcurrentbranch = Nothing
+ , cachedgitenv = Nothing
}
{- Makes an Annex state object for the specified git repo.
@@ -241,10 +243,10 @@ changeState modifier = do
mvar <- ask
liftIO $ modifyMVar_ mvar $ return . modifier
-withState :: (AnnexState -> (AnnexState, b)) -> Annex b
+withState :: (AnnexState -> IO (AnnexState, b)) -> Annex b
withState modifier = do
mvar <- ask
- liftIO $ modifyMVar mvar $ return . modifier
+ liftIO $ modifyMVar mvar modifier
{- Sets a flag to True -}
setFlag :: String -> Annex ()