@@ -549,14 +549,16 @@ shakeOpen lspEnv defaultConfig logger debouncer
549
549
return ideState
550
550
551
551
startTelemetry :: ShakeDatabase -> ShakeExtras -> IO (Async () )
552
- startTelemetry db ShakeExtras {.. }
552
+ startTelemetry db extras @ ShakeExtras {.. }
553
553
| userTracingEnabled = do
554
554
countKeys <- mkValueObserver " cached keys count"
555
555
countDirty <- mkValueObserver " dirty keys count"
556
556
countBuilds <- mkValueObserver " builds count"
557
+ IdeOptions {optCheckParents} <- getIdeOptionsIO extras
558
+ checkParents <- optCheckParents
557
559
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
560
562
shakeGetBuildStep db >>= observe countBuilds
561
563
562
564
| otherwise = async (pure () )
@@ -759,26 +761,28 @@ getHiddenDiagnostics IdeState{shakeExtras = ShakeExtras{hiddenDiagnostics}} = do
759
761
-- * exports map
760
762
garbageCollectDirtyKeys :: Action [Key ]
761
763
garbageCollectDirtyKeys = do
762
- IdeOptions {optMaxDirtyAge} <- getIdeOptions
763
- garbageCollectDirtyKeysOlderThan optMaxDirtyAge
764
+ IdeOptions {optCheckParents, optMaxDirtyAge} <- getIdeOptions
765
+ checkParents <- liftIO optCheckParents
766
+ garbageCollectDirtyKeysOlderThan optMaxDirtyAge checkParents
764
767
765
768
garbageCollectKeysNotVisited :: Action [Key ]
766
769
garbageCollectKeysNotVisited = do
767
- IdeOptions {optMaxDirtyAge} <- getIdeOptions
768
- garbageCollectKeysNotVisitedFor optMaxDirtyAge
770
+ IdeOptions {optCheckParents, optMaxDirtyAge} <- getIdeOptions
771
+ checkParents <- liftIO optCheckParents
772
+ garbageCollectKeysNotVisitedFor optMaxDirtyAge checkParents
769
773
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
772
776
dirtySet <- fromMaybe [] <$> getDirtySet
773
- garbageCollectKeys " dirty GC" maxAge dirtySet
777
+ garbageCollectKeys " dirty GC" maxAge checkParents dirtySet
774
778
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
777
781
keys <- getKeysAndVisitedAge
778
- garbageCollectKeys " not visited GC" maxAge keys
782
+ garbageCollectKeys " not visited GC" maxAge checkParents keys
779
783
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
782
786
start <- liftIO offsetTime
783
787
extras <- getShakeExtras
784
788
(n:: Int , garbage ) <- liftIO $ modifyVar (state extras) $ \ vmap ->
@@ -793,10 +797,33 @@ garbageCollectKeys label maxAge agedKeys = do
793
797
where
794
798
removeDirtyKey st@ (vmap,(! counter, keys)) (k, age)
795
799
| age > maxAge
800
+ , fromKeyType k `notElem` preservedKeys checkParents
796
801
, (True , vmap') <- HMap. alterF (\ prev -> (isJust prev, Nothing )) k vmap
797
802
= (vmap', (counter+ 1 , k: keys))
798
803
| otherwise = st
799
804
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
+
800
827
-- | Define a new Rule without early cutoff
801
828
define
802
829
:: IdeRule k v
0 commit comments