Displayio slow draw speeds

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
raven_coda
 
Posts: 3
Joined: Sun Jul 03, 2022 12:01 am

Displayio slow draw speeds

Post 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.

User avatar
blakebr
 
Posts: 1266
Joined: Tue Apr 17, 2012 6:23 pm

Re: Displayio slow draw speeds

Post by blakebr »

Tracking

User avatar
blakebr
 
Posts: 1266
Joined: Tue Apr 17, 2012 6:23 pm

Re: Displayio slow draw speeds

Post 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

User avatar
raven_coda
 
Posts: 3
Joined: Sun Jul 03, 2022 12:01 am

Re: Displayio slow draw speeds

Post 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)

User avatar
blakebr
 
Posts: 1266
Joined: Tue Apr 17, 2012 6:23 pm

Re: Displayio slow draw speeds

Post by blakebr »

Thank you!

User avatar
tannewt
 
Posts: 3405
Joined: Thu Oct 06, 2016 8:48 pm

Re: Displayio slow draw speeds

Post 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.)

User avatar
raven_coda
 
Posts: 3
Joined: Sun Jul 03, 2022 12:01 am

Re: Displayio slow draw speeds

Post 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.

User avatar
tannewt
 
Posts: 3405
Joined: Thu Oct 06, 2016 8:48 pm

Re: Displayio slow draw speeds

Post 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.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”