[squeak-dev] Squeak on a cellphone may need better blocking behavior

Marcel Taeumel marcel.taeumel at hpi.de
Wed Sep 2 08:52:20 UTC 2020


Hi all.

If one does not depend on accurate timing for animations, it would be possible to re-design WorldState >> #doOneCycle to go to sleep after each cycle, only waking up if some (unknown) delay or event triggers from another Squeak process. We could design events for Morph >> #changed and also Morphic stepping, as Vanessa explained. Maybe the stepping logic could be handled in an extra process altogether. Not sure about the Tweak approach because not sure about the scheduling efficiency when facing loads (!) of Squeak processes. :-)

User input is -- basically -- event-driven already. See EventSensor >> #eventTickler, #nextEvent and HandMorph >> #processEvent. There is just a "polling layer" on top of it to make it compatible with the Morphic main loop (i.e. #doOneCycle). If that event-tickler process would still consume too much CPU time, there is a rough sketch of an "inputSemaphore" in the image. See EventSensor >> #primSetInputSemaphore:. However, one would have to double-check the VM code whether that semaphore is signaled in all cases on all platforms. Then, even the event-tickler process could avoid the use of a fixed delay. Then, the VM would tell the image when it is time to call #primGetNextEvent:. No unnecessary polling.

Best,
Marcel
Am 02.09.2020 03:28:11 schrieb Vanessa Freudenberg <vanessa at codefrau.net>:
On Tue, Sep 1, 2020 at 8:36 AM Eliot Miranda <eliot.miranda at gmail.com [mailto:eliot.miranda at gmail.com]> wrote:

Hi Tony,


> On Sep 1, 2020, at 6:50 AM, Tony Garnock-Jones <tonyg at leastfixedpoint.com [mailto:tonyg at leastfixedpoint.com]> wrote:
>
> It occurs to me that to get better power efficiency, Squeak may need to
> learn how to go to sleep more often. At present it's using about a
> quarter of a core on my phone when I'm not doing anything to it.
>
> JIT could help that, I guess; but more generally, it'd be nice just not
> to be awake when there's nothing pressing to do...

The solution is a modified event architecture and jettisoning relinquishProcessorForMilliseconds:.  Search the archives (squeak-dev & vm-dev) for “event driven vm”.  This is work that should have been done a long time ago (I did this for the VisualWorks vm back at the turn of the century or thereabouts).  But it isn’t going to get done unless someone steps up.  My input queue is full to overflowing.


Not just the VM, but we would also need to modify the image to be event-driven.

A lot of Morphic code works by polling for changes in state (typically in a "step" method), rather than reacting to events. That is almost elegant in its simplicity, but rather wasteful. It was designed before power consumption became an issue we care about. Nowadays, Morphs should only be stepping if they are actively animating something without user input. 

Basically, the UI process should sleep until there is an event, which could be a user event, a timer event, or some asynchronous state change (like a network package arrived, etc).

I guess Morphic can accommodate that, or it might need a larger re-design. E.g. Tweak was designed around every UI element running in a separate thread, and sleeping until there was actually something to do.

- Vanessa - 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200902/583e5228/attachment.html>


More information about the Squeak-dev mailing list