Skip to content

Separate heap for image data, and RAM tmp filesystem#27

Open
MichaelBell wants to merge 3 commits intopimoroni:dev-jan-2026from
MichaelBell:separate-heaps
Open

Separate heap for image data, and RAM tmp filesystem#27
MichaelBell wants to merge 3 commits intopimoroni:dev-jan-2026from
MichaelBell:separate-heaps

Conversation

@MichaelBell
Copy link

This moves picovector image data out of the Micropython GC heap, significantly improving performance when lots of images are loaded.

At the same time, I've added a simple ramfs implementation, which can be used by apps as a cache (e.g. for data downloaded over wifi that can be fetched again if lost). My Bluesky app uses this for avatars.

The current split is:

  • 3MB Micropython heap
  • 4MB Picovector data
  • 1MB tmp fs

There's clearly tradeoffs here. I think this is a good split for different types of app, but I'm not wedded to them - we can easily to tweak the numbers.

I've used espressif's tlsf for the heap allocation for picovector, and wrapped that in a simple library which initializes the heap on first use. The tlsf library is the same one that Sparkfun's psram heap alloc library uses (but my code is not derived from sparkfun's). I've included tlsf as a submodule - shout if you want that handled differently.

On out of memory, the psram allocator will trigger a Micropython garbage collection. This will generally free up Picovector data, because picovector objects don't release memory until the wrapping Micropython object is garbage collected.

The psram library also includes a cache-bypassing, word at a time memset. This is a bit faster for clearing large blocks of psram than the default memset (and could be used for clearing the framebuffer to a solid colour - but I haven't done that yet).

Because there's now normally less memory on the Micropython heap, garbage collection is faster, so I added gc.collect() to the main badgeware update loop. This gives a more consistent framerate - but maybe should be optional.

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.

1 participant