Skip to content

Commit df21318

Browse files
committed
```
Refactor session loading to handle pending files Introduced a queue to manage pending files during session loading, ensuring that file options are processed in batches. This change improves the efficiency and reliability of session initialization by serializing file processing and avoiding redundant lookups. ```
1 parent c21ce09 commit df21318

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
453453
-- you have to modify 'filesMap' as well.
454454
filesMap <- newVar HM.empty :: IO (Var FilesMap)
455455
-- Version of the mappings above
456+
pendingFilesTQueue <- newTQueueIO
456457
version <- newVar 0
457458
biosSessionLoadingVar <- newVar Nothing :: IO (Var (Maybe SessionLoadingPreferenceConfig))
458459
let returnWithVersion fun = IdeGhcSession fun <$> liftIO (readVar version)
@@ -474,7 +475,6 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
474475
let invalidateShakeCache = do
475476
void $ modifyVar' version succ
476477
return $ toNoFileKey GhcSessionIO
477-
OfInterestVar filesOfInterVar <- getIdeGlobalAction
478478
IdeOptions{ optTesting = IdeTesting optTesting
479479
, optCheckProject = getCheckProject
480480
, optExtensions
@@ -728,31 +728,23 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
728728
sessionOptsList yamlFiles
729729

730730

731-
732731
-- The main function which gets options for a file. We only want one of these running
733732
-- at a time. Therefore the IORef contains the currently running cradle, if we try
734733
-- to get some more options then we wait for the currently running action to finish
735734
-- before attempting to do so.
736-
-- let getOptions :: FilePath -> IO (IdeResult HscEnvEq, [FilePath])
737-
-- getOptions file = do
738-
-- let ncfp = toNormalizedFilePath' (toAbsolutePath file)
739-
-- cachedHieYamlLocation <- HM.lookup ncfp <$> readVar filesMap
740-
-- hieYaml <- cradleLoc file
741-
-- sessionOpts (join cachedHieYamlLocation <|> hieYaml, file) `Safe.catch` \e ->
742-
-- return (([renderPackageSetupException file e], Nothing), maybe [] pure hieYaml)
743-
744735
let getOptionsBatch :: FilePath -> IO (IdeResult HscEnvEq, [FilePath])
745736
getOptionsBatch file' = do
737+
pendingFiles <- atomically $ flushTQueue pendingFilesTQueue
746738
let file = toAbsolutePath file'
747739
hieYaml <- cradleLoc file
748-
filesOfInterest <- HashMap.keys <$> readVar filesOfInterVar
749740
logWith recorder Debug LogSettingInitialDynFlags
750-
results <- getOptionsList (Set.toList $ Set.fromList $ toAbsolutePath file : map fromNormalizedFilePath filesOfInterest)
741+
results <- getOptionsList (Set.toList $ Set.fromList $ toAbsolutePath file : map fromNormalizedFilePath pendingFiles)
751742
return (results Map.! file) `Safe.catch` \e ->
752743
return (([renderPackageSetupException file e], Nothing), maybe [] pure hieYaml)
753744

754745
returnWithVersion $ \file -> do
755746
-- see Note [Serializing runs in separate thread]
747+
atomically $ writeTQueue pendingFilesTQueue file
756748
awaitRunInThread que $ getOptionsBatch file
757749

758750
-- cradleToType :: Cradle Void -> IO ()

0 commit comments

Comments
 (0)