Sped up query commands that read the git-annex branch by around 5%
The only price paid is one additional MVar read per write to the journal. Presumably writing a journal file dominiates over a MVar read time by several orders of magnitude. --batch does not get the speedup because then it needs to notice when another process has made a change. Also made the assistant and other damon modes bypass the optimisation, which would not help them anyway.
This commit is contained in:
parent
aba905152a
commit
aeca7c2207
14 changed files with 101 additions and 25 deletions
|
@ -2,7 +2,7 @@
|
|||
-
|
||||
- Runtime state about the git-annex branch.
|
||||
-
|
||||
- Copyright 2011-2012 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2011-2020 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -29,13 +29,56 @@ checkIndexOnce a = unlessM (indexChecked <$> getState) $ do
|
|||
|
||||
{- Runs an action to update the branch, if it's not been updated before
|
||||
- in this run of git-annex. -}
|
||||
runUpdateOnce :: Annex () -> Annex ()
|
||||
runUpdateOnce a = unlessM (branchUpdated <$> getState) $ do
|
||||
a
|
||||
disableUpdate
|
||||
runUpdateOnce :: Annex () -> Annex BranchState
|
||||
runUpdateOnce a = do
|
||||
st <- getState
|
||||
if branchUpdated st
|
||||
then return st
|
||||
else do
|
||||
a
|
||||
let stf = \st' -> st'
|
||||
{ branchUpdated = True
|
||||
-- The update staged anything that was
|
||||
-- journalled before, so the journal
|
||||
-- does not need to be checked going
|
||||
-- forward, unless new information
|
||||
-- gets written to it, or unless
|
||||
-- this run of git-annex needs to notice
|
||||
-- changes journalled by other processes
|
||||
-- while it's running.
|
||||
, journalIgnorable = not $
|
||||
journalNeverIgnorable st'
|
||||
}
|
||||
changeState stf
|
||||
return (stf st)
|
||||
|
||||
{- Avoids updating the branch. A useful optimisation when the branch
|
||||
- is known to have not changed, or git-annex won't be relying on info
|
||||
- from it. -}
|
||||
disableUpdate :: Annex ()
|
||||
disableUpdate = changeState $ \s -> s { branchUpdated = True }
|
||||
|
||||
{- Called when a change is made to the journal. -}
|
||||
journalChanged :: Annex ()
|
||||
journalChanged = do
|
||||
-- Optimisation: Typically journalIgnorable will already be True
|
||||
-- (when one thing gets journalled, often other things do to),
|
||||
-- so avoid an unnecessary write to the MVar that changeState
|
||||
-- would do.
|
||||
--
|
||||
-- This assumes that another thread is not changing journalIgnorable
|
||||
-- at the same time, but since runUpdateOnce is the only
|
||||
-- thing that changes it, and it only runs once, that
|
||||
-- should not happen.
|
||||
st <- getState
|
||||
when (journalIgnorable st) $
|
||||
changeState $ \st' -> st' { journalIgnorable = False }
|
||||
|
||||
{- When git-annex is somehow interactive, eg in --batch mode,
|
||||
- and needs to always notice changes made to the journal by other
|
||||
- processes, this disables optimisations that avoid normally reading the
|
||||
- journal.
|
||||
-}
|
||||
enableInteractiveJournalAccess :: Annex ()
|
||||
enableInteractiveJournalAccess = changeState $
|
||||
\s -> s { journalNeverIgnorable = True }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue