aboutsummaryrefslogtreecommitdiff
path: root/py/mpconfig.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/mpconfig.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/mpconfig.h')
-rw-r--r--py/mpconfig.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 2fbf1490d..97fc9bb58 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -533,6 +533,20 @@
#define MICROPY_OPT_LOAD_ATTR_FAST_PATH (0)
#endif
+// Use extra RAM to cache map lookups by remembering the likely location of
+// the index. Avoids the hash computation on unordered maps, and avoids the
+// linear search on ordered (especially in-ROM) maps. Can provide a +10-15%
+// performance improvement on benchmarks involving lots of attribute access
+// or dictionary lookup.
+#ifndef MICROPY_OPT_MAP_LOOKUP_CACHE
+#define MICROPY_OPT_MAP_LOOKUP_CACHE (0)
+#endif
+
+// How much RAM (in bytes) to use for the map lookup cache.
+#ifndef MICROPY_OPT_MAP_LOOKUP_CACHE_SIZE
+#define MICROPY_OPT_MAP_LOOKUP_CACHE_SIZE (128)
+#endif
+
// Whether to use fast versions of bitwise operations (and, or, xor) when the
// arguments are both positive. Increases Thumb2 code size by about 250 bytes.
#ifndef MICROPY_OPT_MPZ_BITWISE