Skip to content

Commit ecfabf9

Browse files
committed
py/runtime: make __main__ preallocate to a configurable size
1 parent e4d81eb commit ecfabf9

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
@@ -259,6 +259,11 @@
259259
#define MICROPY_LOADED_MODULES_DICT_SIZE (3)
260260
#endif
261261

262+
// Initial size of __main__ dict
263+
#ifndef MICROPY_MAIN_DICT_SIZE
264+
#define MICROPY_MAIN_DICT_SIZE (1)
265+
#endif
266+
262267
// Whether realloc/free should be passed allocated memory region size
263268
// You must enable this if MICROPY_MEM_STATS is enabled
264269
#ifndef MICROPY_MALLOC_USES_ALLOCATED_SIZE

py/runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void mp_init(void) {
105105
mp_obj_dict_init(&MP_STATE_VM(mp_loaded_modules_dict), MICROPY_LOADED_MODULES_DICT_SIZE);
106106

107107
// initialise the __main__ module
108-
mp_obj_dict_init(&MP_STATE_VM(dict_main), 1);
108+
mp_obj_dict_init(&MP_STATE_VM(dict_main), MICROPY_MAIN_DICT_SIZE);
109109
mp_obj_dict_store(MP_OBJ_FROM_PTR(&MP_STATE_VM(dict_main)), MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__));
110110

111111
// locals = globals for outer module (see Objects/frameobject.c/PyFrame_New())

0 commit comments

Comments
 (0)