From 98a8ff7a1a42211acc62e5c41a445a9d6f256e70 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 22 Jun 2023 17:31:40 +1000 Subject: [PATCH] webassembly: Add support for enabling MICROPY_GC_SPLIT_HEAP_AUTO. When enabled the GC will not reclaim any memory on a call to `gc_collect()`. Instead it will grow the heap. Signed-off-by: Damien George --- ports/webassembly/main.c | 15 +++++++++++++++ ports/webassembly/mpconfigport.h | 1 + 2 files changed, 16 insertions(+) diff --git a/ports/webassembly/main.c b/ports/webassembly/main.c index 1b053046bf..ebde8ac700 100644 --- a/ports/webassembly/main.c +++ b/ports/webassembly/main.c @@ -113,6 +113,19 @@ void mp_js_init_repl() { pyexec_event_repl_init(); } +#if MICROPY_GC_SPLIT_HEAP_AUTO + +// The largest new region that is available to become Python heap. +size_t gc_get_max_new_split(void) { + return 128 * 1024 * 1024; +} + +// Don't collect anything. Instead require the heap to grow. +void gc_collect(void) { +} + +#else + static void gc_scan_func(void *begin, void *end) { gc_collect_root((void **)begin, (void **)end - (void **)begin + 1); } @@ -124,6 +137,8 @@ void gc_collect(void) { gc_collect_end(); } +#endif + #if !MICROPY_VFS mp_lexer_t *mp_lexer_new_from_file(qstr filename) { mp_raise_OSError(MP_ENOENT); diff --git a/ports/webassembly/mpconfigport.h b/ports/webassembly/mpconfigport.h index 6b0f2753a9..d026136239 100644 --- a/ports/webassembly/mpconfigport.h +++ b/ports/webassembly/mpconfigport.h @@ -26,6 +26,7 @@ */ #include +#include // for malloc, for MICROPY_GC_SPLIT_HEAP_AUTO // options to control how MicroPython is built