summaryrefslogtreecommitdiff
path: root/py/runtime.c
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2021-08-19 22:46:40 +1000
committerDamien George <damien@micropython.org>2021-09-16 16:02:15 +1000
commit7b89ad8dbf432ab51eea6d138e179bf51394c786 (patch)
treea94bbd7cd3cdb8e297a6582b7a160789241a8c1e /py/runtime.c
parent910e060f93c02c51a498f57ef77ccbe02566855b (diff)
py/vm: Add a fast path for LOAD_ATTR on instance types.
When the LOAD_ATTR opcode is executed there are quite a few different cases that have to be handled, but the common case is accessing a member on an instance type. Typically, built-in types provide methods which is why this is common. Fortunately, for this specific case, if the member is found in the member map then there's no further processing. This optimisation does a relatively cheap check (type is instance) and then forwards directly to the member map lookup, falling back to the regular path if necessary. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/py/runtime.c b/py/runtime.c
index 27e5bc13e..2f7cf1fa6 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -1081,6 +1081,10 @@ void mp_load_method_maybe(mp_obj_t obj, qstr attr, mp_obj_t *dest) {
dest[0] = MP_OBJ_NULL;
dest[1] = MP_OBJ_NULL;
+ // Note: the specific case of obj being an instance type is fast-path'ed in the VM
+ // for the MP_BC_LOAD_ATTR opcode. Instance types handle type->attr and look up directly
+ // in their member's map.
+
// get the type
const mp_obj_type_t *type = mp_obj_get_type(obj);