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>
This commit is contained in:
committed by
Damien George
parent
7b89ad8dbf
commit
11ef8f22fe
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user