@@ -549,14 +549,16 @@ shakeOpen lspEnv defaultConfig logger debouncer
549549 return ideState
550550
551551startTelemetry :: ShakeDatabase -> ShakeExtras -> IO (Async () )
552- startTelemetry db ShakeExtras {.. }
552+ startTelemetry db extras @ ShakeExtras {.. }
553553 | userTracingEnabled = do
554554 countKeys <- mkValueObserver " cached keys count"
555555 countDirty <- mkValueObserver " dirty keys count"
556556 countBuilds <- mkValueObserver " builds count"
557+ IdeOptions {optCheckParents} <- getIdeOptionsIO extras
558+ checkParents <- optCheckParents
557559 regularly 1 $ do
558- readVar state >>= observe countKeys . Prelude. length
559- readIORef dirtyKeys >>= observe countDirty . Prelude. length
560+ readVar state >>= observe countKeys . countRelevantKeys checkParents . HMap. keys
561+ readIORef dirtyKeys >>= observe countDirty . countRelevantKeys checkParents . HSet. toList
560562 shakeGetBuildStep db >>= observe countBuilds
561563
562564 | otherwise = async (pure () )
@@ -759,26 +761,28 @@ getHiddenDiagnostics IdeState{shakeExtras = ShakeExtras{hiddenDiagnostics}} = do
759761-- * exports map
760762garbageCollectDirtyKeys :: Action [Key ]
761763garbageCollectDirtyKeys = do
762- IdeOptions {optMaxDirtyAge} <- getIdeOptions
763- garbageCollectDirtyKeysOlderThan optMaxDirtyAge
764+ IdeOptions {optCheckParents, optMaxDirtyAge} <- getIdeOptions
765+ checkParents <- liftIO optCheckParents
766+ garbageCollectDirtyKeysOlderThan optMaxDirtyAge checkParents
764767
765768garbageCollectKeysNotVisited :: Action [Key ]
766769garbageCollectKeysNotVisited = do
767- IdeOptions {optMaxDirtyAge} <- getIdeOptions
768- garbageCollectKeysNotVisitedFor optMaxDirtyAge
770+ IdeOptions {optCheckParents, optMaxDirtyAge} <- getIdeOptions
771+ checkParents <- liftIO optCheckParents
772+ garbageCollectKeysNotVisitedFor optMaxDirtyAge checkParents
769773
770- garbageCollectDirtyKeysOlderThan :: Int -> Action [Key ]
771- garbageCollectDirtyKeysOlderThan maxAge = otTracedGarbageCollection " dirty GC" $ do
774+ garbageCollectDirtyKeysOlderThan :: Int -> CheckParents -> Action [Key ]
775+ garbageCollectDirtyKeysOlderThan maxAge checkParents = otTracedGarbageCollection " dirty GC" $ do
772776 dirtySet <- fromMaybe [] <$> getDirtySet
773- garbageCollectKeys " dirty GC" maxAge dirtySet
777+ garbageCollectKeys " dirty GC" maxAge checkParents dirtySet
774778
775- garbageCollectKeysNotVisitedFor :: Int -> Action [Key ]
776- garbageCollectKeysNotVisitedFor maxAge = otTracedGarbageCollection " not visited GC" $ do
779+ garbageCollectKeysNotVisitedFor :: Int -> CheckParents -> Action [Key ]
780+ garbageCollectKeysNotVisitedFor maxAge checkParents = otTracedGarbageCollection " not visited GC" $ do
777781 keys <- getKeysAndVisitedAge
778- garbageCollectKeys " not visited GC" maxAge keys
782+ garbageCollectKeys " not visited GC" maxAge checkParents keys
779783
780- garbageCollectKeys :: String -> Int -> [(Key , Int )] -> Action [Key ]
781- garbageCollectKeys label maxAge agedKeys = do
784+ garbageCollectKeys :: String -> Int -> CheckParents -> [(Key , Int )] -> Action [Key ]
785+ garbageCollectKeys label maxAge checkParents agedKeys = do
782786 start <- liftIO offsetTime
783787 extras <- getShakeExtras
784788 (n:: Int , garbage ) <- liftIO $ modifyVar (state extras) $ \ vmap ->
@@ -793,10 +797,33 @@ garbageCollectKeys label maxAge agedKeys = do
793797 where
794798 removeDirtyKey st@ (vmap,(! counter, keys)) (k, age)
795799 | age > maxAge
800+ , fromKeyType k `notElem` preservedKeys checkParents
796801 , (True , vmap') <- HMap. alterF (\ prev -> (isJust prev, Nothing )) k vmap
797802 = (vmap', (counter+ 1 , k: keys))
798803 | otherwise = st
799804
805+ countRelevantKeys :: CheckParents -> [Key ] -> Int
806+ countRelevantKeys checkParents =
807+ Prelude. length . filter ((`notElem` preservedKeys checkParents) . fromKeyType)
808+
809+ preservedKeys :: CheckParents -> [Maybe TypeRep ]
810+ preservedKeys checkParents = map Just $
811+ -- always preserved
812+ [ typeOf GetFileExists
813+ , typeOf GetModificationTime
814+ , typeOf GhcSessionIO
815+ , typeOf GetClientSettings
816+ , typeOf AddWatchedFile
817+ ]
818+ ++ concat
819+ -- preserved if CheckParents is enabled since we need to rebuild the ModuleGraph
820+ [ [ typeOf GetModSummary
821+ , typeOf GetModSummaryWithoutTimestamps
822+ , typeOf GetLocatedImports
823+ ]
824+ | checkParents /= NeverCheck
825+ ]
826+
800827-- | Define a new Rule without early cutoff
801828define
802829 :: IdeRule k v
0 commit comments