Skip to content

bit_world: draw without making an Area per shape - #195

Merged
bdbarnett merged 1 commit into
mainfrom
bit-world-no-areas
Nov 20, 2026
Merged

bdbarnett merged 1 commit into
mainfrom
bit-world-no-areas

Conversation

@bdbarnett

Copy link
Copy Markdown
Contributor

bit_world draws hundreds of shapes a frame, and every pygraphics drawing call used to hand back a new Area, 32 bytes each on MicroPython. The app never reads them, so its canvases now ask pygraphics not to make them (FrameBuffer(..., areas=False), from PyDevices/pygraphics#105). With a pygraphics that doesn't know the keyword yet, gfx_frame() falls back to the plain constructor, so the app runs the same on every release.

On unix MicroPython at 800x480, bytes allocated per frame drop from 983 to 498 in the Workshop, 587 to 414 in Sky Ruins and 762 to 528 in the Cyber-Deck. What's left is mostly float maths in the acts. repaint_check still finds every frame identical to a full repaint (885 fast frames, 0 bad), and the CPython tests pass with the released pygraphics and with the branch.

The board numbers are in the comment below.

Refs #189

Bit World never reads the Area a pygraphics drawing call returns, so its
pygraphics frames ask for none (FrameBuffer areas=False, pygraphics#104).
On MicroPython that removes the garbage left by text, alpha glows and
large copies. A pygraphics without the keyword returns them as before.

On unix MicroPython with pygraphics#105, update, sound and repaint into
two alternating 800x480 buffers allocate, per frame: Workshop 983 -> 498
bytes, Sky Ruins 587 -> 414, Cyber-Deck 762 -> 528. tests/repaint_check.py
prints bad 0 at 800x480, and the CPython tests pass with the released
pygraphics (the fallback) and with pygraphics#105.

Refs #189
@bdbarnett

Copy link
Copy Markdown
Contributor Author

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.

@bdbarnett
bdbarnett merged commit b1894e3 into main Nov 20, 2026
14 checks passed
@bdbarnett
bdbarnett deleted the bit-world-no-areas branch November 20, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant