From e14f4d0caddc5dcb49afd9352534a15312b5c257 Mon Sep 17 00:00:00 2001 From: Vladimir Smitka Date: Sun, 23 Aug 2026 18:32:01 +0000 Subject: [PATCH 1/2] ports/zephyr-cp: enable LOAD_ATTR_FAST_PATH and MAP_LOOKUP_CACHE The make-based ports get these two interpreter options from py/circuitpy_mpconfig.mk: LOAD_ATTR_FAST_PATH defaults to 1 and MAP_LOOKUP_CACHE to CIRCUITPY_FULL_BUILD. The zephyr-cp port does not include that makefile, so neither macro was ever defined - and py/vm.c and py/map.c test them with #if, where an undefined identifier is 0. Both optimizations were therefore silently off on this port. Define them in build_circuitpython.py next to the other interpreter flags, with the same values the classic ports use. Measured on RP2350 (Fruit Jam): method and attribute access microbenchmarks improve about 25%, closing most of the interpreter gap against ports/raspberrypi. --- ports/zephyr-cp/cptools/build_circuitpython.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ports/zephyr-cp/cptools/build_circuitpython.py b/ports/zephyr-cp/cptools/build_circuitpython.py index 55c069a1ddc..5343a4898d5 100644 --- a/ports/zephyr-cp/cptools/build_circuitpython.py +++ b/ports/zephyr-cp/cptools/build_circuitpython.py @@ -369,6 +369,12 @@ async def build_circuitpython(): # noqa: C901 lto = cmake_args.get("LTO", "n") == "y" circuitpython_flags.append(f"-DCIRCUITPY_ENABLE_MPY_NATIVE={1 if enable_mpy_native else 0}") circuitpython_flags.append(f"-DCIRCUITPY_FULL_BUILD={1 if full_build else 0}") + # These two are set by py/circuitpy_mpconfig.mk on the make-based ports (LOAD_ATTR_FAST_PATH + # defaults to 1, MAP_LOOKUP_CACHE to CIRCUITPY_FULL_BUILD). This port does not include that + # makefile, so they were never defined - and py/vm.c and py/map.c test them with #if, where an + # undefined identifier is 0. Both interpreter optimisations were therefore off here. + circuitpython_flags.append("-DCIRCUITPY_OPT_LOAD_ATTR_FAST_PATH=1") + circuitpython_flags.append(f"-DCIRCUITPY_OPT_MAP_LOOKUP_CACHE={1 if full_build else 0}") circuitpython_flags.append(f"-DCIRCUITPY_SETTINGS_TOML={1 if full_build else 0}") circuitpython_flags.append(f"-DMICROPY_PY_ASYNC_AWAIT={1 if full_build else 0}") circuitpython_flags.append(f"-DMICROPY_PY_ASYNCIO={1 if full_build else 0}") From 1e342d3ddbc049419f1a3ad89753537100260760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Smitka?= Date: Mon, 24 Aug 2026 22:29:43 +0200 Subject: [PATCH 2/2] Update ports/zephyr-cp/cptools/build_circuitpython.py Co-authored-by: Scott Shawcroft --- ports/zephyr-cp/cptools/build_circuitpython.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ports/zephyr-cp/cptools/build_circuitpython.py b/ports/zephyr-cp/cptools/build_circuitpython.py index 5343a4898d5..edc9422377b 100644 --- a/ports/zephyr-cp/cptools/build_circuitpython.py +++ b/ports/zephyr-cp/cptools/build_circuitpython.py @@ -369,10 +369,6 @@ async def build_circuitpython(): # noqa: C901 lto = cmake_args.get("LTO", "n") == "y" circuitpython_flags.append(f"-DCIRCUITPY_ENABLE_MPY_NATIVE={1 if enable_mpy_native else 0}") circuitpython_flags.append(f"-DCIRCUITPY_FULL_BUILD={1 if full_build else 0}") - # These two are set by py/circuitpy_mpconfig.mk on the make-based ports (LOAD_ATTR_FAST_PATH - # defaults to 1, MAP_LOOKUP_CACHE to CIRCUITPY_FULL_BUILD). This port does not include that - # makefile, so they were never defined - and py/vm.c and py/map.c test them with #if, where an - # undefined identifier is 0. Both interpreter optimisations were therefore off here. circuitpython_flags.append("-DCIRCUITPY_OPT_LOAD_ATTR_FAST_PATH=1") circuitpython_flags.append(f"-DCIRCUITPY_OPT_MAP_LOOKUP_CACHE={1 if full_build else 0}") circuitpython_flags.append(f"-DCIRCUITPY_SETTINGS_TOML={1 if full_build else 0}")