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:
Joey Hess 2020-04-09 13:54:43 -04:00
parent aba905152a
commit aeca7c2207
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
14 changed files with 101 additions and 25 deletions

View file

@ -42,6 +42,7 @@ import Data.ByteString.Builder
import Control.Concurrent (threadDelay)
import Annex.Common
import Types.BranchState
import Annex.BranchState
import Annex.Journal
import Annex.GitOverlay
@ -123,7 +124,7 @@ getBranch = maybe (hasOrigin >>= go >>= use) return =<< branchsha
{- Ensures that the branch and index are up-to-date; should be
- called before data is read from it. Runs only once per git-annex run. -}
update :: Annex ()
update :: Annex BranchState
update = runUpdateOnce $ void $ updateTo =<< siblingBranches
{- Forces an update even if one has already been run. -}
@ -221,8 +222,10 @@ updateTo' pairs = do
- Returns an empty string if the file doesn't exist yet. -}
get :: RawFilePath -> Annex L.ByteString
get file = do
update
getLocal file
st <- update
if journalIgnorable st
then getRef fullname file
else getLocal file
{- Like get, but does not merge the branch, so the info returned may not
- reflect changes in remotes.
@ -274,7 +277,9 @@ maybeChange file f = lockJournal $ \jl -> do
{- Records new content of a file into the journal -}
set :: Journalable content => JournalLocked -> RawFilePath -> content -> Annex ()
set = setJournalFile
set jl f c = do
journalChanged
setJournalFile jl f c
{- Commit message used when making a commit of whatever data has changed
- to the git-annex brach. -}
@ -359,7 +364,7 @@ commitIndex' jl branchref message basemessage retrynum parents = do
- that have not been committed yet. There may be duplicates in the list. -}
files :: Annex [RawFilePath]
files = do
update
_ <- update
-- ++ forces the content of the first list to be buffered in memory,
-- so use getJournalledFilesStale which should be much smaller most
-- of the time. branchFiles will stream as the list is consumed.