Skip to content

bit_world: the picture stops for a quarter second about every 8 s on an ESP32-S31 board #189

Closed

Description

@bdbarnett

On a Waveshare ESP32-S31-Touch-LCD-4.3C (320 MHz, 16 MB octal PSRAM), bit_world's picture visibly stops at intervals while the music carries on.

Measured with the frame timer's own counters (multimer Timer fired, late_max), read over WebREPL before and after a 69 s run with nothing else attached: 1424 frames fired against a 10 ms period, about 20.6 frames a second, and the latest frame was 255 ms late. The audio pump reported no stalls and no dropped buffers over the same run, so the sound is not what blocks.

A short timing hook on the frame callback showed the pattern: about every 8 s one frame takes 230-270 ms, and free heap jumps during it, so a garbage collection runs there. A bare gc.collect() on this board takes about 190 ms with 2.6 MB live in a 14.8 MB heap. About 0.7 s after each of those, a second frame takes 100-360 ms with no collection; what that one waits on is not known yet.

Still open: how much bit_world allocates per frame, and whether cutting that (or collecting in smaller, earlier steps) removes the pause; and the cause of the second slow frame.

Activity

  1. bdbarnett commented on Nov 20, 2026

    @bdbarnett
    ContributorAuthor

    #194 cuts what each frame allocates from about 11.7 KB to 1.3 KB on the ESP32-S31, so a collection runs about once a minute, where it ran every 8 to 17 seconds. Each one still stops the picture for about 250 ms, because the collector scans every pixel buffer the app holds. What's left per frame is mostly pygraphics' Area (PyDevices/pygraphics#104): alpha glows, text and large copies. This issue stays open until that's gone or collections no longer show.

  2. bdbarnett commented on Nov 20, 2026

    @bdbarnett
    ContributorAuthor

    Measured on the ESP32-S31 4.3 inch RGB board, bit_world for 70 s each (direct mode, drawing into the panel's two buffers):

    build bytes per frame collections in 70 s frame gap at a collection gc.collect() with the app alive
    before (released pygraphics, apps main) 3,233 2 (29.7 s, 57.4 s) 306, 294 ms 217 ms
    firmware with pygraphics#105 and omnipython-builds#598, apps main 3,234 1 (57.0 s) 306 ms 218 ms
    same, plus apps#195 (areas=False) 2,822 2 (33.3 s, 63.6 s) 241, 358 ms 208 ms
    same, plus omnipython#728's framebuffers() patched in 2,773 1 (66.2 s) 364 ms 218 ms

    So the Area change takes about 400 bytes a frame off bit_world, the cached framebuffers() about 50 more, and a collection comes a little less often. The pause doesn't get shorter: each collection still takes about 210-220 ms.

    That length comes from the pixel buffers. On the same board, after a fresh boot, gc.collect() takes 14 ms with an idle heap (grown to 15 MB). It takes 121 ms with three 800x480 RGB565 buffers (2.3 MB) of zeros alive, 128 ms with a gradient in them, and 282 ms when every word in them looks like a heap pointer. MicroPython's collector reads every word of a bytearray looking for pointers. bit_world's three act backgrounds are those 2.3 MB, so they are nearly all of each pause. Keeping big pixel buffers out of the scanned heap is the change that would remove the stall. The ~2.8 KB a frame that's left isn't traced yet (on unix MicroPython the same acts leave about 500 bytes, so most of it is board-side). It only sets how often a collection comes.

  3. bdbarnett commented on Nov 20, 2026

    @bdbarnett
    ContributorAuthor

    Fixed by #198 with the new offheap module (PyDevices/omnipython-builds#602). The frames and sprites now live outside the garbage-collected heap. On the ESP32-S31 4.3" board, a collection with Bit World running fell from about 198 ms to 25 ms, and Bit World went from 12 to 24.6 fps.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions