Skip to content

Garbage collection of dirty keys #2263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
shakeGetDatabaseKeys
  • Loading branch information
pepeiborra committed Oct 26, 2021
commit c2981c005088a4c9e9b735f9ba0d27100320ea84
6 changes: 6 additions & 0 deletions hls-graph/src/Development/IDE/Graph/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Development.IDE.Graph.Database(
shakeRunDatabaseForKeys,
shakeProfileDatabase,
shakeGetBuildStep,
shakeGetDatabaseKeys,
shakeGetDirtySet,
shakeLastBuildKeys
) where
Expand Down Expand Up @@ -47,6 +48,11 @@ shakeGetDirtySet :: ShakeDatabase -> IO [(Key, Int)]
shakeGetDirtySet (ShakeDatabase _ _ db) =
fmap snd <$> Development.IDE.Graph.Internal.Database.getDirtySet db

-- | Returns ann approximation of the database keys,
-- annotated with how long ago (in # builds) they were visited
shakeGetDatabaseKeys :: ShakeDatabase -> IO [(Key, Int)]
shakeGetDatabaseKeys (ShakeDatabase _ _ db) = getKeysAndVisitAge db

-- | Returns the build number
shakeGetBuildStep :: ShakeDatabase -> IO Int
shakeGetBuildStep (ShakeDatabase _ _ db) = do
Expand Down
6 changes: 6 additions & 0 deletions hls-graph/src/Development/IDE/Graph/Internal/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Development.IDE.Graph.Internal.Action
, reschedule
, runActions
, Development.IDE.Graph.Internal.Action.getDirtySet
, getKeysAndVisitedAge
) where

import Control.Concurrent.Async
Expand Down Expand Up @@ -130,3 +131,8 @@ getDirtySet :: Action [(Key, Int)]
getDirtySet = do
db <- getDatabase
liftIO $ fmap snd <$> Development.IDE.Graph.Internal.Database.getDirtySet db

getKeysAndVisitedAge :: Action [(Key, Int)]
getKeysAndVisitedAge = do
db <- getDatabase
liftIO $ Development.IDE.Graph.Internal.Database.getKeysAndVisitAge db
12 changes: 11 additions & 1 deletion hls-graph/src/Development/IDE/Graph/Internal/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}

module Development.IDE.Graph.Internal.Database (newDatabase, incDatabase, build, getDirtySet) where
module Development.IDE.Graph.Internal.Database (newDatabase, incDatabase, build, getDirtySet, getKeysAndVisitAge) where

import Control.Concurrent.Async
import Control.Concurrent.Extra
Expand Down Expand Up @@ -188,6 +188,16 @@ getDirtySet db = do
calcAgeStatus (Dirty x)=calcAge <$> x
calcAgeStatus _ = Nothing
return $ mapMaybe ((secondM.secondM) calcAgeStatus) dbContents

-- | Returns ann approximation of the database keys,
-- annotated with how long ago (in # builds) they were visited
getKeysAndVisitAge :: Database -> IO [(Key, Int)]
getKeysAndVisitAge db = do
values <- Ids.elems (databaseValues db)
Step curr <- readIORef (databaseStep db)
let keysWithVisitAge = mapMaybe (secondM (fmap getAge . getResult)) values
getAge Result{resultVisited = Step s} = curr - s
return keysWithVisitAge
--------------------------------------------------------------------------------
-- Lazy IO trick

Expand Down