aboutsummaryrefslogtreecommitdiff
path: root/py/mpstate.h
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2021-08-18 14:52:48 +1000
committerDamien George <damien@micropython.org>2021-09-16 16:02:19 +1000
commit11ef8f22fe7701cc75b6aaf2386670891eaacf92 (patch)
tree36b8e76771c83b5719ab2a4899c8db29fa02772f /py/mpstate.h
parent7b89ad8dbf432ab51eea6d138e179bf51394c786 (diff)
py/map: Add an optional cache of (map+index) to speed up map lookups.
The existing inline bytecode caching optimisation, selected by MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE, reserves an extra byte in the bytecode after certain opcodes, which at runtime stores a map index of the likely location of this field when looking up the qstr. This scheme is incompatible with bytecode-in-ROM, and doesn't work with native generated code. It also stores bytecode in .mpy files which is of a different format to when the feature is disabled, making generation of .mpy files more complex. This commit provides an alternative optimisation via an approach that adds a global cache for map offsets, then all mp_map_lookup operations use it. It's less precise than bytecode caching, but allows the cache to be independent and external to the bytecode that is executing. It also works for the native emitter and adds a similar performance boost on top of the gain already provided by the native emitter. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'py/mpstate.h')
-rw-r--r--py/mpstate.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/py/mpstate.h b/py/mpstate.h
index 07335bae4..53b290687 100644
--- a/py/mpstate.h
+++ b/py/mpstate.h
@@ -231,6 +231,11 @@ typedef struct _mp_state_vm_t {
// This is a global mutex used to make the VM/runtime thread-safe.
mp_thread_mutex_t gil_mutex;
#endif
+
+ #if MICROPY_OPT_MAP_LOOKUP_CACHE
+ // See mp_map_lookup.
+ uint8_t map_lookup_cache[MICROPY_OPT_MAP_LOOKUP_CACHE_SIZE];
+ #endif
} mp_state_vm_t;
// This structure holds state that is specific to a given thread.