summaryrefslogtreecommitdiff
path: root/py/mpconfig.h
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2021-07-15 15:04:40 +1000
committerDamien George <damien@micropython.org>2022-09-19 19:06:09 +1000
commit3ac8b5851e5f4dade465d52b91ed2ccc17851263 (patch)
tree15132801d2f3ffcb54baf1eec185aa5e86e9bde2 /py/mpconfig.h
parenta52cd5b07d6d6e2502fff2bbfb9e5b96562452a4 (diff)
py/obj: Add slot-index mp_obj_type_t representation.
The existings mp_obj_type_t uses a sparse representation for slots for the capability methods of the type (eg print, make_new). This commit adds a compact slot-index representation. The basic idea is that where the mp_obj_type_t struct used to have 12 pointer fields, it now has 12 uint8_t indices, and a variable-length array of pointers. So in the best case (no fields used) it saves 12x4-12=36 bytes (on a 32-bit machine) and in the common case (three fields used) it saves 9x4-12=24 bytes. Overall with all associated changes, this slot-index representation reduces code size by 1000 to 3000 bytes on bare-metal ports. Performance is marginally better on a few tests (eg about 1% better on misc_pystone.py and misc_raytrace.py on PYBv1.1), but overall marginally worse by a percent or so. See issue #7542 for further analysis and discussion. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'py/mpconfig.h')
-rw-r--r--py/mpconfig.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 698d264d2..0045fa198 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -145,6 +145,13 @@
#define MICROPY_OBJ_IMMEDIATE_OBJS (MICROPY_OBJ_REPR != MICROPY_OBJ_REPR_D)
#endif
+#define MICROPY_OBJ_TYPE_REPR_FULL (0)
+#define MICROPY_OBJ_TYPE_REPR_SLOT_INDEX (1)
+
+#ifndef MICROPY_OBJ_TYPE_REPR
+#define MICROPY_OBJ_TYPE_REPR (MICROPY_OBJ_TYPE_REPR_FULL)
+#endif
+
/*****************************************************************************/
/* Memory allocation policy */