Skip to content

Instantly share code, notes, and snippets.

@erikcorry
Created March 15, 2024 10:44
Show Gist options
  • Save erikcorry/6b913de8cc77ae3275d4d096f2d008eb to your computer and use it in GitHub Desktop.
Save erikcorry/6b913de8cc77ae3275d4d096f2d008eb to your computer and use it in GitHub Desktop.

Memory use, performance, and Toit pixel display.

(March 2024).

Some applications using pixel displays may run out of memory, especially if you are running on a small ESP32 with no external PSRAM. This is especially the case if you are using the small jaguar server on the device for fast edit-compile-run development cycles.

Conversely, if you are running on a device with lots of memory you may improve the performance of the pixel display by using larger buffers.

If you run out of memory you will get stack traces and an overview of memory usage, to help you debug the situation. Be sure to run jag monitor or equivalent so that you can see the debug output in this case. On a base ESP32 with the default image, the Bluetooth stack takes up a lot of RAM. This is the case, even if you are not using Bluetooth. If this is impacting you, you can use an ESP32 envelope that does not include Bluetooth support. This is done for a USB-connected device with

jag flash --chip=esp32-no-bt

or for a Wifi connected device with

jag firmware update --chip=esp32-no-bt

Other envelopes with different C components enabled can be found at https://github.com/toitlang/envelopes/releases

If you have a lot of memory and want to use it to improve display performance, you can update the size of the buffers used to update the pixel display to 10k or even more:

display.max-patch-size = 10_000
@ojmason
Copy link

ojmason commented Apr 26, 2024

How much memory would BT normally use? I'm using an ESP32-C3 with 400kB SRAM, so I'm wondering whether I should avoid it or not. The use case is a GPS tracker that reads location data and sends it over LoRa/BT/Wifi to a base station or other relay stations. So the program itself would not need that much memory, apart from buffering the location data that hasn't been set yet.

@erikcorry
Copy link
Author

As I recall it's about 30k of difference, but of course it can vary by version. You can try the recipe above and then run serial-print-heap-report to see how the memory use changes. See https://medium.com/the-toit-take/get-insight-into-memory-use-on-your-esp32-running-toit-65c62e5b65fd

@ojmason
Copy link

ojmason commented May 2, 2024

Thanks, will try that!

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