Separate heap for image data, and RAM tmp filesystem#27
Open
MichaelBell wants to merge 3 commits intopimoroni:dev-jan-2026from
Open
Separate heap for image data, and RAM tmp filesystem#27MichaelBell wants to merge 3 commits intopimoroni:dev-jan-2026from
MichaelBell wants to merge 3 commits intopimoroni:dev-jan-2026from
Conversation
8d7973e to
cd2ab9e
Compare
aaed313 to
481f956
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.