[squeak-dev] #wait is slow

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Thu Jul 1 17:18:26 UTC 2021

Hi all,

I just made an interesting observation:

[1000 timesRepeat: [0.001 seconds wait]] timeToRun. "--> 2612"

I think the reason for this might be that Delay >> #schedule uses a critical section that is also accessed by the TimerEventLoop process with the highest priority in the system, so the synchronization overhead would be the bottleneck in this case.

Instead, if you need to produce many short delays anyway (for instance, to simulate a running process, just like me right new), you can use a busy-wait instead:

Duration >> busyWait

| proceedTime |
proceedTime := Time utcMicrosecondClock + self asMicroSeconds.
[Time utcMicrosecondClock >= proceedTime] whileFalse

[1000 timesRepeat: [0.001 seconds busyWait]] timeToRun "--> 1000"
Much faster.

Could we need this in the Trunk, too?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210701/98d13364/attachment.html>

More information about the Squeak-dev mailing list