git-annex/Types/CatFileHandles.hs
Joey Hess cee6b344b4
cat-file resource pool
Avoid running a large number of git cat-file child processes when run with
a large -J value.

This implementation takes care to avoid adding any overhead to git-annex
when run without -J. When run with -J, there is a small bit of added
overhead, to manipulate the resource pool. That optimisation added a
fair bit of complexity.
2020-04-20 15:19:31 -04:00

30 lines
745 B
Haskell

{- git-cat file handles pools
-
- Copyright 2020 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Types.CatFileHandles (
CatFileHandles(..),
catFileHandlesNonConcurrent,
catFileHandlesPool,
) where
import Control.Concurrent.STM
import qualified Data.Map as M
import Utility.ResourcePool
import Git.CatFile (CatFileHandle)
data CatFileHandles
= CatFileHandlesNonConcurrent CatMap
| CatFileHandlesPool (TMVar CatMap)
type CatMap = M.Map FilePath (ResourcePool CatFileHandle)
catFileHandlesNonConcurrent :: CatFileHandles
catFileHandlesNonConcurrent = CatFileHandlesNonConcurrent M.empty
catFileHandlesPool :: IO CatFileHandles
catFileHandlesPool = CatFileHandlesPool <$> newTMVarIO M.empty