8000 py/runtime: Make sys.modules preallocate to a configurable size. · micropython/micropython@1a2ffda · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a2ffda

Browse files
matejcikdpgeorge
authored andcommitted
py/runtime: Make sys.modules preallocate to a configurable size.
This allows configuring the pre-allocated size of sys.modules dict, in order to prevent unwanted reallocations at run-time (3 sys-modules is really not quite enough for a larger project).
1 parent b26def0 commit 1a2ffda

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@
229229
#define MICROPY_MODULE_DICT_SIZE (1)
230230
#endif
231231

232+
// Initial size of sys.modules dict
233+
#ifndef MICROPY_LOADED_MODULES_DICT_SIZE
234+
#define MICROPY_LOADED_MODULES_DICT_SIZE (3)
235+
#endif
236+
232237
// Whether realloc/free should be passed allocated memory region size
233238
// You must enable this if MICROPY_MEM_STATS is enabled
234239
#ifndef MICROPY_MALLOC_USES_ALLOCATED_SIZE

py/runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void mp_init(void) {
9191
#endif
9292

9393
// init global module dict
94-
mp_obj_dict_init(&MP_STATE_VM(mp_loaded_modules_dict), 3);
94+
mp_obj_dict_init(&MP_STATE_VM(mp_loaded_modules_dict), MICROPY_LOADED_MODULES_DICT_SIZE);
9595

9696
// initialise the __main__ module
9797
mp_obj_dict_init(&MP_STATE_VM(dict_main), 1);

0 commit comments

Comments
 (0)
0