Skip to content

rgbmatrix: decrease RAM usage over soft resets #3499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jepler opened this issue Oct 1, 2020 · 5 comments
Closed

rgbmatrix: decrease RAM usage over soft resets #3499

jepler opened this issue Oct 1, 2020 · 5 comments

Comments

@jepler
Copy link

jepler commented Oct 1, 2020

.. implement #3498 but for rgbmatrix. will require the same infrastructure commits to be merged in first.

@tannewt
Copy link
Member

tannewt commented Oct 8, 2020

@jepler Do we need to fix this for 6.0.0?

@tannewt tannewt added the bug label Oct 8, 2020
@tannewt tannewt added this to the 6.x.x - Bug Fixes milestone Oct 8, 2020
@jepler
Copy link
Author

jepler commented Oct 8, 2020

No.

@jepler
Copy link
Author

jepler commented Dec 4, 2020

@cwalther was this addressed by the enhancements to supervisor allocations or does it still need to be done?

@cwalther
Copy link

cwalther commented Dec 5, 2020

As far as I understand it is addressed. Looking at a4b84cf, the previous implementation would allocate preferentially on the GC heap, while the new one should reuse previously freed supervisor allocations when possible.

Empirical result: In a quick test I’m seeing considerably less GC memory use after initializing an RGBMatrix display for the second time after a soft reset, so it seems to be effective.

Before:

Adafruit CircuitPython 6.1.0-beta.1-143-g299b6efd8-dirty on 2020-12-05; PewPew M4 CW with samd51G19
>>> import rgbmat_display
158464 880 157584
158464 27776 130688
>>> 
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Hello World!

Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 6.1.0-beta.1-143-g299b6efd8-dirty on 2020-12-05; PewPew M4 CW with samd51G19
>>> import displayio; displayio.release_displays()
>>> import rgbmat_display
132352 960 131392
132352 27840 104512
>>> 
soft reboot

After:

Adafruit CircuitPython 6.1.0-beta.2-5-ga95c972b5-dirty on 2020-12-05; PewPew M4 CW with samd51G19
>>> import rgbmat_display
158464 880 157584
158464 27776 130688
>>> 
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Hello World!

Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 6.1.0-beta.2-5-ga95c972b5-dirty on 2020-12-05; PewPew M4 CW with samd51G19
>>> import displayio; displayio.release_displays()
>>> import rgbmat_display
132288 960 131328
132288 3136 129152
>>> 
soft reboot

rgbmat_display.py:

import displayio
import framebufferio
import rgbmatrix
import gc
import microcontroller.pin as pin

gc.collect();
a, f = gc.mem_alloc(), gc.mem_free()
print(a+f, a, f)

#displayio.release_displays()
rgbm = rgbmatrix.RGBMatrix(width=32, bit_depth=6, rgb_pins=[pin.PB02, pin.PB03, pin.PB08, pin.PB09, pin.PB10, pin.PB11], addr_pins=[pin.PA20, pin.PA21, pin.PA22, pin.PA23], clock_pin=pin.PB22, latch_pin=pin.PB23, output_enable_pin=pin.PA27)
display = framebufferio.FramebufferDisplay(rgbm, auto_refresh=True)

gc.collect()
a, f = gc.mem_alloc(), gc.mem_free()
print(a+f, a, f)

@jepler jepler closed this as completed Dec 7, 2020
@jepler
Copy link
Author

jepler commented Dec 7, 2020

excellent, thank you again

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

No branches or pull requests

3 participants