@@ -16,7 +16,7 @@ module Development.IDE.Graph.Internal.Scheduler
1616 , reportTotalCount
1717 , isDirty
1818 , isRunDepChangedOne
19- , doAction
19+ , doPrepareAction
2020 ) where
2121
2222import Control.Concurrent.STM (STM , atomically ,
@@ -83,14 +83,14 @@ prepareToRunKey key db =
8383
8484data PrepareAction a k = PrepareActionNothing | PrepareActionPending a Int | PrepareActionReady a
8585
86- doAction :: Database -> PrepareAction (Key , RunMode , Maybe Result ) Key -> STM (Maybe (Key , RunMode , Maybe Result ))
87- doAction _ PrepareActionNothing = pure Nothing
88- doAction (Database {.. }) (PrepareActionReady (key, runMode, mRes) ) = do
86+ doPrepareAction :: Database -> PrepareAction (Key , RunMode , Maybe Result ) Key -> STM (Maybe (Key , RunMode , Maybe Result ))
87+ doPrepareAction _ PrepareActionNothing = pure Nothing
88+ doPrepareAction (Database {.. }) (PrepareActionReady (key, runMode, mRes) ) = do
8989 let SchedulerState {.. } = databaseScheduler
9090 SMap. delete key schedulerRunningPending
9191 pure $ Just (key, runMode, mRes)
9292
93- doAction (Database {.. }) (PrepareActionPending (key, runMode, mRes) pendingCount) = do
93+ doPrepareAction (Database {.. }) (PrepareActionPending (key, runMode, mRes) pendingCount) = do
9494 let SchedulerState {.. } = databaseScheduler
9595 SMap. insert (pendingCount, runMode, mRes) key schedulerRunningPending
9696 pure Nothing
@@ -101,7 +101,7 @@ prepareToRunKeyCached db@Database {..} cache0 key = do
101101 let SchedulerState {.. } = databaseScheduler
102102 (status, cache1) <- lookupStatusCache db key cache0
103103 (cache2, res) <- case keyStatus <$> status of
104- Just (Dirty Nothing ) -> pure (cache1, Just (0 , RunDependenciesChanged , Nothing ))
104+ -- Just (Dirty Nothing) -> pure (cache1, Just (0, RunDependenciesChanged, Nothing))
105105 Just (Dirty (Just r)) -> do
106106 -- todo we use final deps instead of runtime deps here
107107 -- does it cause in compatiable issues?
@@ -151,30 +151,28 @@ prepareToRunKeyCached db@Database {..} cache0 key = do
151151-- prepareToRunKeys :: Database -> IO [Key]
152152prepareToRunKeys db = do
153153 let SchedulerState {.. } = databaseScheduler db
154- dirties <- atomically $
155- -- dbNotLocked db
156- flushTQueue schedulerUpsweepQueue
154+ dirties <- atomically $ flushTQueue schedulerUpsweepQueue
157155 -- let dirtiesList = chunksOf 1 dirties
158156 let dirtiesList = toNChunks 8 dirties
159157 -- We need to make sure what is the good number of dirtis for a batch
160158 -- maybe we should make it dynamic based on the total number of dirties
161- (t1, toRunsList ) <- duration $ flip mapConcurrently dirtiesList $ \ ks -> do
162- atomically $ fst <$> foldM (\ (result, cache) k -> do
159+ (t1, res ) <- duration $ flip mapConcurrently dirtiesList $ \ ks -> do
160+ toRuns <- atomically $ fst <$> foldM (\ (result, cache) k -> do
163161 (nresult, ncache) <- prepareToRunKeyCached db cache k
164162 return (nresult: result, ncache)
165163 ) ([] , mempty ) ks
164+ res <- forM toRuns $ \ k -> atomically $ doPrepareAction db k
165+ return res
166166 -- (t1, toRunsList) <- duration $ forM dirtiesList $ \ks -> do
167167 -- atomically $ fst <$> foldM (\(result, cache) k -> do
168168 -- (nresult, ncache) <- prepareToRunKeyCached db cache k
169169 -- return (nresult: result, ncache)
170170 -- ) ([], mempty) ks
171171 -- dbNotLocked db
172- (t2, res) <- duration $ forM toRunsList $ \ toRuns -> forM toRuns $ \ k -> do
173172 -- we would potentially missed an acition here decreasePendingCount
174173 -- if this is not running fast enough
175- atomically $ doAction db k
176174 (t3, () ) <- duration $ atomically $ TPQ. fromList schedulerRunningReady [(0 ,(k, a, b)) | r <- res, (k, a, b) <- catMaybes r]
177- return ((t1,t2 ,t3), dirties)
175+ return ((t1,0 ,t3), dirties)
178176 where
179177 toNChunks n xs = go xs
180178 where
0 commit comments