eez-open / studio

Cross-platform low-code GUI and automation
https://www.envox.eu/studio/studio-introduction/
GNU General Public License v3.0
299 stars 69 forks source link

[LVGL] Add options to improve memory usage of LVGL projects #277

Open fietser28 opened 11 months ago

fietser28 commented 11 months ago

Current implementation creates all LVGL screens, widgets and corresponding flow states and variables at startup and keeps them active in memory. This requires a large LVGL memory pool if the amount of screens/widgets grows, even if the screen is only showed once or rarely. Even for simple screens the LVGL memory is considerable.

The same applies to the flow states, but I'm not sure if there is much to be gained here in effort vs. memory usage reduction.

Example use case: Raspberry Pi Pico with 264KBytes of RAM and 2MBytes of FLASH. The flow has 7 screens (of 320x240) with around 100 widgets, 50 native variables and 25 local variables in total. Static memory allocations are now:

I suspect this is a common issue with a lot of MCU's where RAM is limited.

Point of attention: Will the LVGL memory pool implementation keep the fragmentation low to keep functioning properly with a limited pool size?

mvladic commented 1 month ago

I implemented support for uncompressed assets data.

Until now, so called assets data (pages, flows, global variables, ... definitions) was stored in compressed (LZ4) form in FLASH memory and decompression of that data was done during startup in RAM or SDRAM and after that used from there. This was done in that way because it was wanted to optimize the consumption of FLASH memory with the assumption that there is a large SDRAM memory. Since it is mainly read only data (i.e. only global variables are read write) it makes sense to keep it all the time in the FLASH memory if one wants to optimize RAM consumption. In order to achieve this, assets data must be written to flash in uncompressed form. To store assets data uncompressed inside FLASH memory following changes are required:

There is also some changes in eez-framework to support this, so pull the latest version.

mvladic commented 1 month ago

Flow execution queue size can be adjusted also. By default, memory for 1000 entries is reserved. You can change this to some smaller value by putting the following line in eez-framework-conf.h that you can place next to lv_conf.h:

#define EEZ_FLOW_QUEUE_SIZE 250

But, you must determine value that works for you empirically. You can get the max. value used so far by calling eez::flow::getMaxQueueSize().