Page 1 of 1
Displayio slow draw speeds
Posted: Sun Jul 03, 2022 12:08 am
by raven_coda
I'm doing some benchmarks and found the displayio module very slow. I'm hoping it is because I don't understand how to use the library efficiently. Using the following displayio I code I only get 3 FPS
Code: Select all
display_bus = displayio.FourWire(spi, command=board.GP20, chip_select=board.GP22, reset=board.GP21, baudrate=100000000)
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240, auto_refresh=False)
cb = displayio.Bitmap(320,240,1_)
cp = displayio.Palette(1)
bgs=displayio.TileGrid(cb, pixel_shader=cp, x=0, y=0)
group.append(bgs)
while True:
cp[0] = 0xFF0000
display.refresh()
cp[0] = 0x0000FF
display.refresh()
However, if I use the following code to send the data directly to the fourwire interface I get 21 FPS, 7x the speed.
Code: Select all
while True:
display_bus.send(0x2A, b"\0\0\x01\x40")
display_bus.send(0x2b, b"\0\0\0\xf0")
display_bus.send(0x2c, b"\xFC\0"*240*320)
display_bus.send(0x2A, b"\0\0\x01\x40")
display_bus.send(0x2b, b"\0\0\0\xf0")
display_bus.send(0x2c, b"\0\x3F"*240*320)
Is there a way I could make the displayio library more performant? For reference, I'm using the RP2040 which has more than enough RAM to hold a frame buffer in memory if that would address the issue.
Re: Displayio slow draw speeds
Posted: Sun Jul 03, 2022 1:53 pm
by blakebr
Tracking
Re: Displayio slow draw speeds
Posted: Mon Jul 04, 2022 3:50 pm
by blakebr
raven_coda,
Can you post your entire code.py file. I just got an ILI3941 and I would like to see how you made it work.
Thanks,
Bruce
Re: Displayio slow draw speeds
Posted: Mon Jul 04, 2022 9:31 pm
by raven_coda
Here is a more polished version
Code: Select all
import board
import displayio
import adafruit_ili9341
import time
from busio import SPI
direct = False #change this to true to compare
displayio.release_displays()
spi = SPI(clock=board.GP18, MOSI=board.GP19, MISO=board.GP16)
display_bus = displayio.FourWire(spi, command=board.GP20, chip_select=board.GP22, reset=board.GP21,baudrate=125000000)
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240, auto_refresh=False)
group = displayio.Group()
display.show(group)
cb = displayio.Bitmap(320,240,1_)
cp = displayio.Palette(1)
cp[0] = 0x00FF00
bgs=displayio.TileGrid(cb, pixel_shader=cp, x=0, y=0)
group.append(bgs)
while True:
start = time.monotonic()
for i in range(10):
if direct:
display_bus.send(0x2A, b"\0\0\x01\x40")
display_bus.send(0x2b, b"\0\0\0\xf0")
display_bus.send(0x2c, b"\xFC\0"*240*320)
display_bus.send(0x2A, b"\0\0\x01\x40")
display_bus.send(0x2b, b"\0\0\0\xf0")
display_bus.send(0x2c, b"\0\x3F"*240*320)
else:
display.refresh()
cp[0] = 0x0000FF
display.refresh()
cp[0] = 0xFF0000
span = time.monotonic()-start
print(20 / span)
Re: Displayio slow draw speeds
Posted: Tue Jul 05, 2022 2:08 pm
by blakebr
Thank you!
Re: Displayio slow draw speeds
Posted: Tue Jul 05, 2022 3:21 pm
by tannewt
raven_coda wrote:I'm doing some benchmarks and found the displayio module very slow.
Is there a way I could make the displayio library more performant? For reference, I'm using the RP2040 which has more than enough RAM to hold a frame buffer in memory if that would address the issue.
displayio isn't designed to be performant when updating the entire display. It trades speed for reduced memory use by computing pixels as need and in chunks. It also does dirty rectangle tracking for you to know where to update. Dirty rectangle tracking reduces data transferred to displays that have their own framebuffer. displayio is used across many microcontrollers so it isn't easy to rewrite for the rp2040.
What are you actually trying to do with displayio? Your benchmark is one of the worst cases. (Reading pixels from a file with OnDiskBitmap can also be very slow.)
Re: Displayio slow draw speeds
Posted: Wed Jul 06, 2022 10:36 am
by raven_coda
I was just doing some benchmarks but the end goal is to implement a tile-based side scroller game. Since most of the screen would need updating I don't think the dirty rectangle optimization will work for my needs. Thanks for the reply though.
Re: Displayio slow draw speeds
Posted: Wed Jul 06, 2022 2:19 pm
by tannewt
For side scrolling I had intended on supporting the built in scroll ability of displays. However, it is only one direction usually and often it is the wrong axis.