Skip to content

Commit dec8dc8

Browse files
committed
io-sim: evaluate deschedule & reschedule to WHNF
This shows a 4.5% performance improvement on connection manager & inbound governor simulation tests. ```
1 parent e8876c6 commit dec8dc8

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
@@ -207,7 +207,7 @@ schedule !thread@Thread{
207207

208208
ForkFrame -> do
209209
-- this thread is done
210-
trace <- deschedule Terminated thread simstate
210+
!trace <- deschedule Terminated thread simstate
211211
return $ SimTrace time tid tlbl EventThreadFinished
212212
$ SimTrace time tid tlbl (EventDeschedule Terminated)
213213
$ trace
@@ -217,7 +217,7 @@ schedule !thread@Thread{
217217
let thread' = thread { threadControl = ThreadControl (k x) ctl'
218218
, threadMasking = maskst' }
219219
-- but if we're now unmasked, check for any pending async exceptions
220-
trace <- deschedule Interruptable thread' simstate
220+
!trace <- deschedule Interruptable thread' simstate
221221
return $ SimTrace time tid tlbl (EventMask maskst')
222222
$ SimTrace time tid tlbl (EventDeschedule Interruptable)
223223
$ trace
@@ -245,7 +245,7 @@ schedule !thread@Thread{
245245

246246
| otherwise -> do
247247
-- An unhandled exception in any other thread terminates the thread
248-
trace <- deschedule Terminated thread simstate
248+
!trace <- deschedule Terminated thread simstate
249249
return $ SimTrace time tid tlbl (EventThrow e)
250250
$ SimTrace time tid tlbl (EventThreadUnhandled e)
251251
$ SimTrace time tid tlbl (EventDeschedule Terminated)
@@ -426,7 +426,7 @@ schedule !thread@Thread{
426426
-- For testing, we should have a more sophisticated policy to show
427427
-- that algorithms are not sensitive to the exact policy, so long
428428
-- as it is a fair policy (all runnable threads eventually run).
429-
trace <- deschedule Yield thread' simstate' { nextVid = nextVid' }
429+
!trace <- deschedule Yield thread' simstate' { nextVid = nextVid' }
430430
return $ SimTrace time tid tlbl (EventTxCommitted
431431
written' created' Nothing)
432432
$ traceMany
@@ -447,13 +447,13 @@ schedule !thread@Thread{
447447
StmTxAborted _read e -> do
448448
-- schedule this thread to immediately raise the exception
449449
let thread' = thread { threadControl = ThreadControl (Throw e) ctl }
450-
trace <- schedule thread' simstate
450+
!trace <- schedule thread' simstate
451451
return $ SimTrace time tid tlbl (EventTxAborted Nothing) trace
452452

453453
StmTxBlocked read -> do
454454
!_ <- mapM_ (\(SomeTVar tvar) -> blockThreadOnTVar tid tvar) read
455455
vids <- traverse (\(SomeTVar tvar) -> labelledTVarId tvar) read
456-
trace <- deschedule Blocked thread simstate
456+
!trace <- deschedule Blocked thread simstate
457457
return $ SimTrace time tid tlbl (EventTxBlocked vids Nothing)
458458
$ SimTrace time tid tlbl (EventDeschedule Blocked)
459459
$ trace
@@ -481,7 +481,7 @@ schedule !thread@Thread{
481481
(runIOSim action')
482482
(MaskFrame k maskst ctl)
483483
, threadMasking = maskst' }
484-
trace <-
484+
!trace <-
485485
case maskst' of
486486
-- If we're now unmasked then check for any pending async exceptions
487487
Unmasked -> SimTrace time tid tlbl (EventDeschedule Interruptable)
@@ -508,7 +508,7 @@ schedule !thread@Thread{
508508
-- exception and the source thread id to the pending async exceptions.
509509
let adjustTarget t = t { threadThrowTo = (e, Labelled tid tlbl) : threadThrowTo t }
510510
threads' = Map.adjust adjustTarget tid' threads
511-
trace <- deschedule Blocked thread' simstate { threads = threads' }
511+
!trace <- deschedule Blocked thread' simstate { threads = threads' }
512512
return $ SimTrace time tid tlbl (EventThrowTo e tid')
513513
$ SimTrace time tid tlbl EventThrowToBlocked
514514
$ SimTrace time tid tlbl (EventDeschedule Blocked)
@@ -620,7 +620,7 @@ deschedule Terminated !thread !simstate@SimState{ curTime = time, threads } = do
620620
let wakeup = map (l_labelled . snd) (reverse (threadThrowTo thread))
621621
(unblocked,
622622
simstate') = unblockThreads wakeup simstate
623-
trace <- reschedule simstate'
623+
!trace <- reschedule simstate'
624624
return $ traceMany
625625
[ (time, tid', tlbl', EventThrowToWakeup)
626626
| tid' <- unblocked

0 commit comments

Comments
 (0)