-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
preload branches into the branch cache when switching projects
- Loading branch information
1 parent
736ccf1
commit 951f318
Showing
7 changed files
with
63 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
parser-typechecker/src/Unison/Codebase/SqliteCodebase/ProjectRootCache.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- | Simple cache which just keeps the last n relevant project branches in memory. | ||
-- The Branch Cache handles all the lookups of the actual branch data by hash, this cache serves only to keep the last | ||
-- n accessed branches in memory so they don't get garbage collected. See the Branch Cache for more context. | ||
-- | ||
-- This speeds up switching back and forth between project branches, and also serves to keep the current project branch | ||
-- in memory so it won't be cleaned up by the Branch Cache, since the Branch Cache only keeps | ||
-- a weak reference to the current branch and we no longer keep the actual branch in LoopState. | ||
module Unison.Codebase.SqliteCodebase.ProjectRootCache | ||
( newProjectRootCache, | ||
stashBranch, | ||
) | ||
where | ||
|
||
import Control.Concurrent.STM | ||
import Unison.Codebase.Branch | ||
import Unison.Prelude | ||
|
||
data ProjectRootCache m = ProjectRootCache {capacity :: Int, cached :: TVar [Branch m]} | ||
|
||
newProjectRootCache :: (MonadIO m) => Int -> m (ProjectRootCache n) | ||
newProjectRootCache capacity = do | ||
var <- liftIO $ newTVarIO [] | ||
pure (ProjectRootCache capacity var) | ||
|
||
stashBranch :: (MonadIO n) => ProjectRootCache m -> Branch m -> n () | ||
stashBranch ProjectRootCache {capacity, cached} branch = do | ||
liftIO . atomically $ do | ||
modifyTVar cached $ \branches -> take capacity (branch : filter (/= branch) branches) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters