summaryrefslogtreecommitdiffstatshomepage
path: root/py/emitglue.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-10-25 15:07:02 +0100
committerDamien George <damien.p.george@gmail.com>2014-10-25 20:23:13 +0100
commit1084b0f9c21b093618da4494508dec9ca8467e35 (patch)
treee21a6e19240346b6a449b432cbf961d7839fba4b /py/emitglue.c
parentfcff4663dd5bd33eed931c7731fd133f49551b4b (diff)
downloadmicropython-1084b0f9c21b093618da4494508dec9ca8467e35.tar.gz
micropython-1084b0f9c21b093618da4494508dec9ca8467e35.zip
py: Store bytecode arg names in bytecode (were in own array).
This saves a lot of RAM for 2 reasons: 1. For functions that don't have default values, var args or var kw args (which is a large number of functions in the general case), the mp_obj_fun_bc_t type now fits in 1 GC block (previously needed 2 because of the extra pointer to point to the arg_names array). So this saves 16 bytes per function (32 bytes on 64-bit machines). 2. Combining separate memory regions generally saves RAM because the unused bytes at the end of the GC block are saved for 1 of the blocks (since that block doesn't exist on its own anymore). So generally this saves 8 bytes per function. Tested by importing lots of modules: - 64-bit Linux gave about an 8% RAM saving for 86k of used RAM. - pyboard gave about a 6% RAM saving for 31k of used RAM.
Diffstat (limited to 'py/emitglue.c')
-rw-r--r--py/emitglue.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/py/emitglue.c b/py/emitglue.c
index dd31de925b..41a6720e70 100644
--- a/py/emitglue.c
+++ b/py/emitglue.c
@@ -55,26 +55,20 @@ mp_raw_code_t *mp_emit_glue_new_raw_code(void) {
return rc;
}
-void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, byte *code, mp_uint_t len, mp_uint_t n_pos_args, mp_uint_t n_kwonly_args, qstr *arg_names, mp_uint_t scope_flags) {
+void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, byte *code, mp_uint_t len, mp_uint_t n_pos_args, mp_uint_t n_kwonly_args, mp_uint_t scope_flags) {
rc->kind = MP_CODE_BYTECODE;
rc->scope_flags = scope_flags;
rc->n_pos_args = n_pos_args;
rc->n_kwonly_args = n_kwonly_args;
- rc->arg_names = arg_names;
rc->u_byte.code = code;
rc->u_byte.len = len;
#ifdef DEBUG_PRINT
DEBUG_printf("assign byte code: code=%p len=" UINT_FMT " n_pos_args=" UINT_FMT " n_kwonly_args=" UINT_FMT " flags=%x\n", code, len, n_pos_args, n_kwonly_args, (uint)scope_flags);
- DEBUG_printf(" arg names:");
- for (int i = 0; i < n_pos_args + n_kwonly_args; i++) {
- DEBUG_printf(" %s", qstr_str(arg_names[i]));
- }
- DEBUG_printf("\n");
#endif
#if MICROPY_DEBUG_PRINTERS
if (mp_verbose_flag > 0) {
- mp_bytecode_print(rc, code, len);
+ mp_bytecode_print(rc, n_pos_args + n_kwonly_args, code, len);
}
#endif
}
@@ -121,7 +115,7 @@ mp_obj_t mp_make_function_from_raw_code(mp_raw_code_t *rc, mp_obj_t def_args, mp
mp_obj_t fun;
switch (rc->kind) {
case MP_CODE_BYTECODE:
- fun = mp_obj_new_fun_bc(rc->scope_flags, rc->arg_names, rc->n_pos_args, rc->n_kwonly_args, def_args, def_kw_args, rc->u_byte.code);
+ fun = mp_obj_new_fun_bc(rc->scope_flags, rc->n_pos_args, rc->n_kwonly_args, def_args, def_kw_args, rc->u_byte.code);
break;
#if MICROPY_EMIT_NATIVE
case MP_CODE_NATIVE_PY: