@@ -19,49 +19,26 @@ import Development.IDE.Types.Location
19
19
import GHC.Generics
20
20
21
21
-- | 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 )
45
25
46
26
47
27
unionKnownTargets :: 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')
50
30
51
31
mkKnownTargets :: [(Target , HashSet NormalizedFilePath )] -> KnownTargets
52
- mkKnownTargets vs = KnownTargets (HMap. fromList vs) ( HMap. fromList [(k,k) | (k,_) <- vs ])
32
+ mkKnownTargets vs = KnownTargets (HMap. fromList vs)
53
33
54
34
instance 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` ()
59
36
60
37
instance Hashable KnownTargets where
61
- hashWithSalt s (KnownTargets hm _ ) = hashWithSalt s hm
38
+ hashWithSalt s (KnownTargets hm) = hashWithSalt s hm
62
39
63
40
emptyKnownTargets :: KnownTargets
64
- emptyKnownTargets = KnownTargets HMap. empty HMap. empty
41
+ emptyKnownTargets = KnownTargets HMap. empty
65
42
66
43
data Target = TargetModule ModuleName | TargetFile NormalizedFilePath
67
44
deriving ( Eq , Ord , Generic , Show )
0 commit comments