From 58e0f4ac50b3dc732cbfe0d7b04bb41951ac1329 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 23 Sep 2015 10:50:43 +0100 Subject: py: Allocate parse nodes in chunks to reduce fragmentation and RAM use. With this patch parse nodes are allocated sequentially in chunks. This reduces fragmentation of the heap and prevents waste at the end of individually allocated parse nodes. Saves roughly 20% of RAM during parse stage. --- py/compile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'py/compile.c') diff --git a/py/compile.c b/py/compile.c index 797d7a95e..a3e8c49d1 100644 --- a/py/compile.c +++ b/py/compile.c @@ -3317,7 +3317,7 @@ STATIC void scope_compute_things(scope_t *scope) { } } -mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, uint emit_opt, bool is_repl) { +mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, uint emit_opt, bool is_repl) { // put compiler state on the stack, it's relatively small compiler_t comp_state = {0}; compiler_t *comp = &comp_state; @@ -3326,7 +3326,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, uint emit_opt, bool is comp->is_repl = is_repl; // create the module scope - scope_t *module_scope = scope_new_and_link(comp, SCOPE_MODULE, pn, emit_opt); + scope_t *module_scope = scope_new_and_link(comp, SCOPE_MODULE, parse_tree->root, emit_opt); // optimise constants (scope must be set for error messages to work) comp->scope_cur = module_scope; @@ -3485,7 +3485,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, uint emit_opt, bool is #endif // free the parse tree - mp_parse_node_free(module_scope->pn); + mp_parse_tree_clear(parse_tree); // free the scopes mp_raw_code_t *outer_raw_code = module_scope->raw_code; -- cgit v1.2.3