Skip to content

Commit 98a8ff7

Browse files
committed
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 <[email protected]>
1 parent ae6bcc9 commit 98a8ff7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ports/webassembly/main.c

+15
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ void mp_js_init_repl() {
113113
pyexec_event_repl_init();
114114
}
115115

116+
#if MICROPY_GC_SPLIT_HEAP_AUTO
117+
118+
// The largest new region that is available to become Python heap.
119+
size_t gc_get_max_new_split(void) {
120+
return 128 * 1024 * 1024;
121+
}
122+
123+
// Don't collect anything. Instead require the heap to grow.
124+
void gc_collect(void) {
125+
}
126+
127+
#else
128+
116129
static void gc_scan_func(void *begin, void *end) {
117130
gc_collect_root((void **)begin, (void **)end - (void **)begin + 1);
118131
}
@@ -124,6 +137,8 @@ void gc_collect(void) {
124137
gc_collect_end();
125138
}
126139

140+
#endif
141+
127142
#if !MICROPY_VFS
128143
mp_lexer_t *mp_lexer_new_from_file(qstr filename) {
129144
mp_raise_OSError(MP_ENOENT);

ports/webassembly/mpconfigport.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
#include <stdint.h>
29+
#include <stdlib.h> // for malloc, for MICROPY_GC_SPLIT_HEAP_AUTO
2930

3031
// options to control how MicroPython is built
3132

0 commit comments

Comments
 (0)