aboutsummaryrefslogtreecommitdiff
path: root/Git
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 /Git
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 'Git')
-rw-r--r--Git/Env.hs26
1 files changed, 15 insertions, 11 deletions
diff --git a/Git/Env.hs b/Git/Env.hs
index f41f3ad0e..7e5a2b242 100644
--- a/Git/Env.hs
+++ b/Git/Env.hs
@@ -18,22 +18,26 @@ import Utility.Env
- does not have any gitEnv yet. -}
adjustGitEnv :: Repo -> ([(String, String)] -> [(String, String)]) -> IO Repo
adjustGitEnv g adj = do
- e <- maybe copyenv return (gitEnv g)
+ e <- maybe copyGitEnv return (gitEnv g)
let e' = adj e
return $ g { gitEnv = Just e' }
where
- copyenv = do
+
+{- Copies the current environment, so it can be adjusted when running a git
+ - command. -}
+copyGitEnv :: IO [(String, String)]
+copyGitEnv = do
#ifdef __ANDROID__
- {- This should not be necessary on Android, but there is some
- - weird getEnvironment breakage. See
- - https://github.com/neurocyte/ghc-android/issues/7
- - Use getEnv to get some key environment variables that
- - git expects to have. -}
- let keyenv = words "USER PATH GIT_EXEC_PATH HOSTNAME HOME"
- let getEnvPair k = maybe Nothing (\v -> Just (k, v)) <$> getEnv k
- catMaybes <$> forM keyenv getEnvPair
+ {- This should not be necessary on Android, but there is some
+ - weird getEnvironment breakage. See
+ - https://github.com/neurocyte/ghc-android/issues/7
+ - Use getEnv to get some key environment variables that
+ - git expects to have. -}
+ let keyenv = words "USER PATH GIT_EXEC_PATH HOSTNAME HOME"
+ let getEnvPair k = maybe Nothing (\v -> Just (k, v)) <$> getEnv k
+ catMaybes <$> forM keyenv getEnvPair
#else
- getEnvironment
+ getEnvironment
#endif
addGitEnv :: Repo -> String -> String -> IO Repo