Skip to content

Conversation

@dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Feb 7, 2026

#10277 added background task running during display refresh. However, it didn't guard against background refresh during an explicit foreground refresh. This caused display programs with an explicit .refresh() to run about twice as slow as before.

I was going to add some refresh_in_progress field to the display struct, but discovered it was already there, and that displayio_display_core_start_refresh() was already set up to check for recursive refresh. We just weren't checking its return value. I added that check.

@bablokb This particular slowness was not affected by SD card USB presentation being enabled or not. I think that is a separate problem.

Somewhat random test program, derived from a Learn Guide sample, I used on PyPortal Titano to test:
import board
import displayio
import terminalio
import time

from adafruit_display_text import label

display = board.DISPLAY

WIDTH = display.width
HEIGHT = display.height
BORDER = 2

# Make the display context
splash = displayio.Group()
display.root_group = splash

color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF  # White

bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)

# Draw a smaller inner rectangle in black
inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x000000  # Black
inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER)
splash.append(inner_sprite)

# Draw some white squares
sm_bitmap = displayio.Bitmap(8, 8, 1)
sm_square = displayio.TileGrid(sm_bitmap, pixel_shader=color_palette, x=58, y=17)
splash.append(sm_square)

med_bitmap = displayio.Bitmap(16, 16, 1)
med_square = displayio.TileGrid(med_bitmap, pixel_shader=color_palette, x=71, y=15)
splash.append(med_square)

lrg_bitmap = displayio.Bitmap(32, 32, 1)
lrg_square = displayio.TileGrid(lrg_bitmap, pixel_shader=color_palette, x=91, y=28)
splash.append(lrg_square)

# Draw some label text
text1 = str(time.monotonic())
text_area = label.Label(terminalio.FONT, text=text1, color=0xFFFFFF, x=8, y=8)
splash.append(text_area)
text2 = "SH1107"
text_area2 = label.Label(terminalio.FONT, text=text2, scale=2, color=0xFFFFFF, x=9, y=44)
splash.append(text_area2)

while True:
    start = time.monotonic()
    text_area.text = str(time.monotonic())
    text_area2.text = str(time.monotonic())
    color_palette[0] = 0 if color_palette[0] != 0 else 0xffffff
    display.refresh()
    print(time.monotonic() - start)

@bablokb
Copy link

bablokb commented Feb 8, 2026

@bablokb This particular slowness was not affected by SD card USB presentation being enabled or not. I think that is a separate problem.

I never claimed this was affected by SD card USB presentation. But in issue #10733 I also documented that CP is running 20-30% slower even without SD card and/or host. That is why I linked #10733 to #10277. But maybe we even have a third problem.

@dhalbert
Copy link
Collaborator Author

dhalbert commented Feb 8, 2026

I never claimed this was affected by SD card USB presentation.

Sorry, I didn't mean to imply that you claimed that. Yes, I think there are at least two, if not more, causes of slowdowns. Working on the SD slowdown is next on my list.

@dhalbert dhalbert requested a review from tannewt February 8, 2026 20:03
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dhalbert dhalbert merged commit cdd0cdd into adafruit:main Feb 9, 2026
570 checks passed
@dhalbert dhalbert deleted the prevent-recursive-display-refresh branch February 9, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

i2cdisplaybus + 10.0.3 is twice slower than 9.2.9

3 participants