Repository navigation
MicroPython: LVGL asserts cost 44 KB less flash - #19
Merged
Merged
Conversation
The assert handler from #13 passed the full source path, the line and the function name, and each of LVGL's ~1,230 assert sites tested the weak handler before calling it. On an ESP32-S3 that added 50.8 KB to the firmware (23 KB of code, 20 KB of function names, 6 KB of paths). With CONFIG_SPIRAM_XIP_FROM_PSRAM, where ESP-IDF copies code and constants into PSRAM in 64 KB pages, it pushed both over a page boundary and took 128 KB from the heap. Now each site passes the file's base name (__FILE_NAME__, or __FILE__ on a compiler without it) and the line to a noreturn handler: a load, a move and a call. The message is "LVGL assert failed at lv_display.c:614". Built for ESP32_GENERIC_S3, the growth over v9.5.53 is 6.3 KB and stays within the same pages. The smoke test triggers an assert (set_tile_cnt(256)) on MicroPython, checks the message and that LVGL keeps working; it fails against the previous handler.
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.
The assert handler from #13 made every LVGL assert site pass the full source path, the line and the function name, after testing that the weak handler exists. LVGL has about 1,230 of those sites in an ESP32-S3 build, so the firmware grew by 50.8 KB: 23 KB of code, 20 KB of function names and 6 KB of paths. On a board built with
CONFIG_SPIRAM_XIP_FROM_PSRAM, ESP-IDF copies code and constants into PSRAM in 64 KB pages, and the growth pushed both over a page boundary, which took 128 KB from the heap (#10).Now each site passes only the file's base name (
__FILE_NAME__, falling back to__FILE__on a compiler without it) and the line, to a handler declarednoreturn, so a site is a load, a move and a call. File and line are enough to find the assert. The message becomesRuntimeError: LVGL assert failed at lv_display.c:614. Every MicroPython build links the handler (micropython.cmakeandmicropython.mkboth list it), so it no longer needs to be weak. CircuitPython and CPython builds are unchanged.Built for ESP32_GENERIC_S3 (SPIRAM_OCT, ESP-IDF 5.5.4) with only the LVGL module, the firmware is 6.3 KB larger than v9.5.53 instead of 50.8 KB, and code and constants stay in v9.5.53's 30 + 10 pages.
__FILE_NAME__is defined by every compiler we checked: GCC 13 (unix), arm-none-eabi 14.2, xtensa and riscv32 esp 14.2, mingw 13 and emscripten's clang. On a unix build the new smoke test callsset_tile_cnt(256), gets the RuntimeError with the file and line, and goes on to create a label and refresh; against the previous handler it fails on the message.pytest tests ports/micropython/tests ports/circuitpython/testsandscripts/verify_bindings.shpass. Not run on a board.