From ec87d2d21d781e1db97525e72b6fec738660793d Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Mon, 31 Mar 2025 10:46:48 +0300 Subject: [PATCH] fix(core): presize `__main__` module to avoid heap fragmentation [no changelog] --- core/embed/projects/firmware/mpconfigport.h | 1 + core/embed/projects/unix/mpconfigport.h | 1 + docs/core/misc/fragmentation.md | 2 ++ 3 files changed, 4 insertions(+) diff --git a/core/embed/projects/firmware/mpconfigport.h b/core/embed/projects/firmware/mpconfigport.h index 89b4a67233..5c69a1bc6b 100644 --- a/core/embed/projects/firmware/mpconfigport.h +++ b/core/embed/projects/firmware/mpconfigport.h @@ -41,6 +41,7 @@ #define MICROPY_ALLOC_PATH_MAX (128) #define MICROPY_ENABLE_PYSTACK (1) #define MICROPY_LOADED_MODULES_DICT_SIZE (160) +#define MICROPY_MAIN_DICT_SIZE (8) // emitters #define MICROPY_PERSISTENT_CODE_LOAD (0) diff --git a/core/embed/projects/unix/mpconfigport.h b/core/embed/projects/unix/mpconfigport.h index a2b7463946..a409abad36 100644 --- a/core/embed/projects/unix/mpconfigport.h +++ b/core/embed/projects/unix/mpconfigport.h @@ -46,6 +46,7 @@ #define MICROPY_MEM_STATS (1) #define MICROPY_ENABLE_PYSTACK (1) #define MICROPY_LOADED_MODULES_DICT_SIZE (160) +#define MICROPY_MAIN_DICT_SIZE (8) // emitters #define MICROPY_PERSISTENT_CODE_LOAD (0) diff --git a/docs/core/misc/fragmentation.md b/docs/core/misc/fragmentation.md index 6233db88d4..49eeb641b8 100644 --- a/docs/core/misc/fragmentation.md +++ b/docs/core/misc/fragmentation.md @@ -49,6 +49,8 @@ Micropython to preallocate 160 slots in `mpconfigport.h` variable `trezor.utils`, so if we ever need more modules than that, the test suite _should_ catch it. +Presizing is also applied to `__main__` module by setting `MICROPY_MAIN_DICT_SIZE`. + ## Top-level and function-local imports In order to keep the imported image size in check, in certain places we avoid importing