[Pharo-project] Waste of CPU Power by polling events?
John M McIntosh
johnmci at smalltalkconsulting.com
Fri Nov 26 05:25:13 CET 2010
On 2010-11-23, at 1:23 AM, Henrik Sperre Johansen wrote:
> On 22.11.2010 22:08, Guido Stepken wrote:
>> Need additional:
> You could try checking out how the iOS code does support for complex events.
> It's of course somewhat apple-specific, but hey, would be nice to have the same image-side representation and handling of touch-based events if possible.
Apple is very very notification &event callback oriented in their iOS platform. It sleeps until you touch, then you get a touch event, you process and go back to sleep. Heck if your startup time takes too many seconds Apple nails you.
For Squeak on iOS I take the touch data place on a queue and signals the event semaphore. When the squeak image polls for the event we
turn the touch data into a complex event and pass it back, then is processed by the Smalltalk code to turn into synthetic mouse events. (or something).
For keyboard entry, we take the key input data and turn into synthetic keystroke events, and again signal the semaphore and put on a queue for later when
the Smalltalk code wakes up and calls getnextevent to see what's up.
I'm not sure if anyone mentioned the other issue is that the polling loop also deals with doing the morphic redrawing so it runs a cycle of doing I think it is
50 iterations a second.
For WikiServer which doesn't show a squeak UI I could cut that back to doing a cycle every second or so.
Oh and yet one more thing, the clock tick is yet another issue, some platforms assume they can run an interrupt 1000 a second (or more) to ensure the VM is responsive to Delay being correctly woken up to the microsecond. "PS here I am over simplify the issue & complexity of the issue" but on underpowered hardware the issues of how ioRelinquishProcessorForMicroseconds and the millisecond timer work become messy issues in relationship to CPU usage.
John M. McIntosh <johnmci at smalltalkconsulting.com> Twitter: squeaker68882
Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com
More information about the Pharo-project