Skip to content

Commit d6643e2

Browse files
committed
Remove reads (@michaelpj suggestion)
After ===== ``` STM transaction statistics (2021-12-12 22:11:20.016977 UTC): Transaction Commits Retries Ratio _anonymous_ 15227 116 0.01 action queue - pop 2 2 1.00 actionQueue - done 2 0 0.00 actionQueue - peek 29 0 0.00 actionQueue - push 2 0 0.00 builder 282373 771 0.00 compute 16882 32 0.00 debouncer 6864 215 0.03 define - dirtyKeys 16900 0 0.00 define - read 1 10710 3 0.00 define - read 2 6254 3 0.00 define - write 6248 1 0.00 diagnostics - hidden 6893 10 0.00 diagnostics - publish 4006 200 0.05 diagnostics - read 6901 1 0.00 diagnostics - update 6893 22 0.00 incDatabase 10966 0 0.00 lastValueIO 4 2200 0 0.00 lastValueIO 5 2200 0 0.00 recordProgress 31238 387 0.01 recordProgress2 31238 79 0.00 updateReverseDeps 64994 387 0.01 ```
1 parent fb614bd commit d6643e2

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

ghcide/src/Development/IDE/Core/ProgressReporting.hs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ module Development.IDE.Core.ProgressReporting
1515

1616
import Control.Concurrent.Async
1717
import Control.Concurrent.STM.Stats (TVar, atomicallyNamed,
18-
newTVarIO, readTVar,
19-
readTVarIO, writeTVar)
18+
modifyTVar', newTVarIO,
19+
readTVarIO)
2020
import Control.Concurrent.Strict
2121
import Control.Monad.Extra
2222
import Control.Monad.IO.Class
@@ -86,14 +86,12 @@ recordProgress :: InProgressState -> NormalizedFilePath -> (Int -> Int) -> IO ()
8686
recordProgress InProgressState{..} file shift = do
8787
(prev, new) <- atomicallyNamed "recordProgress" $ STM.focus alterPrevAndNew file currentVar
8888
atomicallyNamed "recordProgress2" $ do
89-
done <- readTVar doneVar
90-
todo <- readTVar todoVar
9189
case (prev,new) of
92-
(Nothing,0) -> writeTVar doneVar (done+1) >> writeTVar todoVar (todo+1)
93-
(Nothing,_) -> writeTVar todoVar (todo+1)
90+
(Nothing,0) -> modifyTVar' doneVar (+1) >> modifyTVar' todoVar (+1)
91+
(Nothing,_) -> modifyTVar' todoVar (+1)
9492
(Just 0, 0) -> pure ()
95-
(Just 0, _) -> writeTVar doneVar (done-1)
96-
(Just _, 0) -> writeTVar doneVar (done+1)
93+
(Just 0, _) -> modifyTVar' doneVar pred
94+
(Just _, 0) -> modifyTVar' doneVar (+1)
9795
(Just _, _) -> pure()
9896
where
9997
alterPrevAndNew = do

0 commit comments

Comments
 (0)