Skip to content

Commit ff24488

Browse files
committed
io-sim: optimise thread termination
It turns out that the most time is spend in `deschedule Terminated` case (>16% of time). This patch makes `unblockThreads` and `reschedule` (in case of time progression) more strict. This has from 1% up to 3% performance improvement.
1 parent ea952b2 commit ff24488

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

io-sim/src/Control/Monad/IOSim/Internal.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ deschedule Sleep _thread _simstate =
672672
-- schedule the next one to run.
673673
reschedule :: SimState s a -> ST s (SimTrace a)
674674
reschedule !simstate@SimState{ runqueue, threads }
675-
| Just (tid, runqueue') <- Deque.uncons runqueue =
675+
| Just (!tid, runqueue') <- Deque.uncons runqueue =
676676
{-# SCC "reschedule.Just" #-}
677677
assert (invariant Nothing simstate) $
678678

@@ -729,15 +729,15 @@ unblockThreads !wakeup !simstate@SimState {runqueue, threads} =
729729
})
730730
where
731731
-- can only unblock if the thread exists and is blocked (not running)
732-
unblocked = [ tid
733-
| tid <- wakeup
734-
, case Map.lookup tid threads of
735-
Just Thread { threadBlocked = True } -> True
736-
_ -> False
737-
]
732+
!unblocked = [ tid
733+
| tid <- wakeup
734+
, case Map.lookup tid threads of
735+
Just Thread { threadBlocked = True } -> True
736+
_ -> False
737+
]
738738
-- and in which case we mark them as now running
739-
threads' = List.foldl'
740-
(flip (Map.adjust (\t -> t { threadBlocked = False })))
739+
!threads' = List.foldl'
740+
(flip (Map.adjust (\t -> t { threadBlocked = False })))
741741
threads unblocked
742742

743743

0 commit comments

Comments
 (0)