Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Un update of a vectorio object palette slow down the microcontroller indefinitely #9666

Open
CDarius opened this issue Sep 27, 2024 · 1 comment

Comments

@CDarius
Copy link

CDarius commented Sep 27, 2024

CircuitPython version

Adafruit CircuitPython 9.1.4 on 2024-09-17; M5Stack Dial with ESP32S3

Code/REPL

import time
import board
import displayio
import vectorio

display = board.DISPLAY

def show_and_count_loops_per_second(num_reads: int) -> None:
    time_ms = time.monotonic_ns() // 1e6
    next_lps_time = time_ms + 1000
    lps_counter = 0

    while num_reads > 0:
        lps_counter += 1
        time_ms = time.monotonic_ns() // 1e6
        if time_ms > next_lps_time:
            print(f"Loops per second: {lps_counter}")
            num_reads -= 1
            next_lps_time += 1000
            lps_counter = 0        

print("Empty loop")
show_and_count_loops_per_second(5)

print("\nCreate a vectorio rectangle as big as the screen")
palette = displayio.Palette(1)
palette[0] = 0x125690
rectangle = vectorio.Rectangle(pixel_shader=palette, width=display.width, height=display.height, x=0, y=0)
rectangle_group = displayio.Group()
rectangle_group.append(rectangle)
display.root_group = rectangle_group

show_and_count_loops_per_second(5)

print("\nChange rectangle color")
palette[0] = 0xFFFF00
show_and_count_loops_per_second(5)

Behavior

Empty loop
Loops per second: 64892
Loops per second: 64707
Loops per second: 64781
Loops per second: 64704
Loops per second: 64682

Create a vectorio rectangle as big as the screen
Loops per second: 64931
Loops per second: 74644
Loops per second: 74662
Loops per second: 74627
Loops per second: 74573

Change rectangle color
Loops per second: 8342
Loops per second: 8644
Loops per second: 8801
Loops per second: 8806
Loops per second: 8698

Description

There's something wrong with the vectorio display update, once the palette color change the microcontroller slow down and never recover. To replicate the bug I made the above example.

First the script run an emty loop and measure how many loops are performed in a second. It runs about 65k loops per second,

After the script create a rectangle with vectiorio as big as the screen and measure the looping time again. Now it runs about 75k loops per second. It make sense, the display do not show anymore the console.

Finally the script change the palette color of the rectange and measure for the third time the empty looping time. The loops per second drop below 9k and never recover even after the screen updates are done

Additional information

No response

@CDarius CDarius added the bug label Sep 27, 2024
@tannewt tannewt added this to the Long term milestone Sep 27, 2024
@tannewt
Copy link
Member

tannewt commented Sep 27, 2024

I suspected this was the palette being marked dirty and then never cleared. BUT it looks like it should be cleared. There may be a bug further upstream that is preventing the palette dirty bit from being cleared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants