pimoroni / EnviroPlus-FeatherWing

CircuitPython library for the Enviro+ FeatherWing
https://shop.pimoroni.com/products/enviro-plus-featherwing
MIT License
10 stars 11 forks source link

plotter enhancements - fill for redraw and inhibit refresh during drawing #23

Closed kevinjwalters closed 2 years ago

kevinjwalters commented 3 years ago

CircuitPython 5.3.0 gained a fill method which is faster as it's implemented in compiled code in the interpreter.

https://github.com/pimoroni/EnviroPlus-FeatherWing/blob/c707f1f23a3a49835644b195e7b7fd58ec914198/library/pimoroni_envirowing/screen/plotter.py#L146-L149

fill() can replace this as long as it's ok to make the code require 5.3.0 or above.

If auto_refresh is on (likely) then it could be inhibited during the draw operations to make the updates more efficient as there's near zero value in an interim partial screen refresh.

Add auto_show to control repeated use of show on the display too, this is only needed once but some code relies on the original behaviour of an invocation of show per draw():

https://github.com/pimoroni/EnviroPlus-FeatherWing/blob/c707f1f23a3a49835644b195e7b7fd58ec914198/library/pimoroni_envirowing/screen/plotter.py#L157

kevinjwalters commented 3 years ago

The current code (second test uses clear bitmap approach rather than redrawing each pixel):

Four lines, 3 ramping took 22.8824 seconds
Four lines, 3 ramping took 143.551 seconds
Three flat lines took 13.0466 seconds
Three flat lines took 158.394 seconds
Two lines, few draws took 12.4685 seconds
Two lines, few draws took 40.4773 seconds

Switching to fill(0) for clearing bitmap:

Four lines, 3 ramping took 22.8771 seconds
Four lines, 3 ramping took 45.201 seconds
Three flat lines took 13.0374 seconds
Three flat lines took 43.8933 seconds
Two lines, few draws took 12.4716 seconds
Two lines, few draws took 16.6502 seconds

Removing unnecessary show() and inhibiting auto_refresh during draw():

Four lines, 3 ramping took 21.0275 seconds
Four lines, 3 ramping took 30.3177 seconds
Three flat lines took 13.0142 seconds
Three flat lines took 29.0123 seconds
Two lines, few draws took 11.9851 seconds
Two lines, few draws took 13.1844 seconds
kevinjwalters commented 3 years ago
kevinjwalters commented 3 years ago

Feather nRF52840 Express running 6.0.0 (Three flat lines uses the default auto_show):

Four lines, 3 ramping took 20.1186 seconds
Four lines, 3 ramping took 15.6292 seconds
Three flat lines took 18.3333 seconds
Three flat lines took 15.2274 seconds
Two lines, few draws took 11.684 seconds
Two lines, few draws took 10.9135 seconds
Alternating, missing took 13.3122 seconds
Alternating, missing took 11.8761 seconds
kevinjwalters commented 3 years ago

Revised test with diffing on undraw re-instated and correct, Feather nRF52840 Express running 6.0.0 (Three flat lines uses the default auto_show):

Four lines, 3 ramping took 20.412 seconds
Four lines, 3 ramping took 15.6498 seconds
Three flat lines took 16.8372 seconds
Three flat lines took 15.1766 seconds
Two lines, few draws took 11.7631 seconds
Two lines, few draws took 10.9154 seconds
Alternating, missing took 13.87 seconds
Alternating, missing took 11.8986 seconds
Gadgetoid commented 2 years ago

Thank you for your efforts here, very, very much appreciated!