Selective collect
#17142
Replies: 1 comment 1 reply
-
Hi @tannewt - this is interesting work, especially as someone that does a bunch of work on C modules etc. I do not have any opinion on the API design at the moment, I would like to understand the intended usage a bit better first. What would be the typical cases where one would use this functionality, and how to decide if to use it or not. I guess any large allocation where the code that allocates knows there will not be any MP objects inside? And I guess the default behavior would have to be "do collection?", to maintain compatibility? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In CircuitPython we're working on supporting our new Fruit Jam board. It uses HSTX to generate DVI video and PSRAM for a larger VM heap (via split heaps). One issue with our demos is that GC collect time gets long enough to chirp audio and stutter video. The heap grows significantly because we store bitmaps and audio buffers in the VM heap.
An idea I had to speed this up was to annotate which VM allocations need to be "collected" (aka scanning for heap pointers.) I've implemented this by adding another table like the one for finalisers. GC times dropped from 80+ms to ~25ms in our test example.
One question I struggled with is how to update the dozen or so memory allocation APIs. Some vary to allocate a struct or a variable length struct. Others vary depending on whether they should raise an error on failure, have a finaliser or zero memory. Now I'm adding a fourth boolean of whether the memory should be collected. What should the APIs be? Can we simplify things by splitting the size computation from the allocation policy?
Existing APIs
micropython/py/misc.h
Lines 70 to 115 in f498a16
micropython/py/obj.h
Lines 922 to 936 in f498a16
Another approach would be to focus on the type of allocations being made.
mp_obj_malloc
is a good example of this. It makes it clear that the allocated memory is a Python object. Therefore it could have finaliser always set and always be collected.How could we unify these allocation APIs to make them easier to maintain? Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions