python-editor-v3 icon indicating copy to clipboard operation
python-editor-v3 copied to clipboard

[Simulator] while True: radio.on() locks up sim

Open microbit-matt-hillsdon opened this issue 3 years ago • 4 comments
trafficstars

while True:
    radio.on()

Appears to lock up the sim.

We should get a change to break out but we don't.

microbit-matt-hillsdon avatar Aug 26 '22 14:08 microbit-matt-hillsdon

This doesn't seem to be an issue when using the simulator demo so perhaps we're just doing much more work on each simulator state change. Perhaps we should RAF rate-limit the simulator state updates.

microbit-matt-hillsdon avatar Aug 26 '22 15:08 microbit-matt-hillsdon

It gets better with useRafState (stoppable again) but you can see re-rendering play out for some time after you click stop. Probably fixable with some re-render optimisation. Probably enough just to push down the listening so we have state fields that are the relevant components of the sim state rather than everything. Or a bunch of memoising. Might be better to try RAF inside the sim.

microbit-matt-hillsdon avatar Aug 26 '22 15:08 microbit-matt-hillsdon

Just tried this and it seemed fine, needs a little more digging at some point.

microbit-matt-hillsdon avatar Oct 06 '22 15:10 microbit-matt-hillsdon

This is still currently an issue for me. The longer you let the while loop run, the worse the effect is as everything waits to catch up. The same thing happens with radio.send(). Forgetting a call to sleep() is probably going to be common error as well.

We only disable the radio on radio.on() in order to reconfigure the radio in drv_radio.c. Can we check whether the configuration has changed and only disabled/re-enable if it has? This won't help in the case of radio.send() so some form of rate-limiting will likely be required.

microbit-robert avatar Oct 11 '22 13:10 microbit-robert