@@ -19,49 +19,26 @@ import Development.IDE.Types.Location
1919import GHC.Generics
2020
2121-- | A mapping of module name to known files
22- data KnownTargets = KnownTargets
23- { targetMap :: ! (HashMap Target (HashSet NormalizedFilePath ))
24- -- | 'normalisingMap' is a cached copy of `HMap.mapKey const targetMap`
25- --
26- -- At startup 'GetLocatedImports' is called on all known files. Say you have 10000
27- -- modules in your project then this leads to 10000 calls to 'GetLocatedImports'
28- -- running concurrently.
29- --
30- -- In `GetLocatedImports` the known targets are consulted and the targetsMap
31- -- is created by mapping the known targets. This map is used for introducing
32- -- sharing amongst filepaths. This operation copies a local copy of the `target`
33- -- map which is local to the rule.
34- --
35- -- @
36- -- let targetsMap = HMap.mapWithKey const targets
37- -- @
38- --
39- -- So now each rule has a 'HashMap' of size 10000 held locally to it and depending
40- -- on how the threads are scheduled there will be 10000^2 elements in total
41- -- allocated in 'HashMap's. This used a lot of memory.
42- --
43- -- Solution: Return the 'normalisingMap' in the result of the `GetKnownTargets` rule so it is shared across threads.
44- , normalisingMap :: ! (HashMap Target Target ) } deriving Show
22+ newtype KnownTargets = KnownTargets
23+ { targetMap :: (HashMap Target (HashSet NormalizedFilePath ))
24+ } deriving (Show , Eq )
4525
4626
4727unionKnownTargets :: KnownTargets -> KnownTargets -> KnownTargets
48- unionKnownTargets (KnownTargets tm nm ) (KnownTargets tm' nm ') =
49- KnownTargets (HMap. unionWith (<>) tm tm') ( HMap. union nm nm')
28+ unionKnownTargets (KnownTargets tm) (KnownTargets tm') =
29+ KnownTargets (HMap. unionWith (<>) tm tm')
5030
5131mkKnownTargets :: [(Target , HashSet NormalizedFilePath )] -> KnownTargets
52- mkKnownTargets vs = KnownTargets (HMap. fromList vs) ( HMap. fromList [(k,k) | (k,_) <- vs ])
32+ mkKnownTargets vs = KnownTargets (HMap. fromList vs)
5333
5434instance NFData KnownTargets where
55- rnf (KnownTargets tm nm) = rnf tm `seq` rnf nm `seq` ()
56-
57- instance Eq KnownTargets where
58- k1 == k2 = targetMap k1 == targetMap k2
35+ rnf (KnownTargets tm) = rnf tm `seq` ()
5936
6037instance Hashable KnownTargets where
61- hashWithSalt s (KnownTargets hm _ ) = hashWithSalt s hm
38+ hashWithSalt s (KnownTargets hm) = hashWithSalt s hm
6239
6340emptyKnownTargets :: KnownTargets
64- emptyKnownTargets = KnownTargets HMap. empty HMap. empty
41+ emptyKnownTargets = KnownTargets HMap. empty
6542
6643data Target = TargetModule ModuleName | TargetFile NormalizedFilePath
6744 deriving ( Eq , Ord , Generic , Show )
0 commit comments