circuitpython/ports
Jim Mussared 525557738c py/builtinimport: Optimise sub-package loading.
This makes it so that sub-packages are resolved relative to their parent's
`__path__`, rather than re-resolving each parent's filesystem path.

The previous behavior was that `import foo.bar` would first re-search
`sys.path` for `foo`, then use the resulting path to find `bar`.

For already-loaded and u-prefixed modules, because we no longer need to
build the path from level to level, we no longer unnecessarily search
the filesystem. This should improve startup time.

Explicitly makes the resolving process clear:
 - Loaded modules are returned immediately without touching the filesystem.
 - Exact-match of builtins are also returned immediately.
 - Then the filesystem search happens.
 - If that fails, then the weak-link handling is applied.

This maintains the existing behavior: if a user writes `import time` they
will get time.py if it exits, otherwise the built-in utime. Whereas `import
utime` will always return the built-in.

This also fixes a regression from a7fa18c203
where we search the filesystem for built-ins. It is now only possible to
override u-prefixed builtins. This will remove a lot of filesystem stats
at startup, as micropython-specific modules (e.g. `pyb`) will no longer
attempt to look at the filesystem.

Added several improvements to the comments and some minor renaming and
refactoring to make it clearer how the import mechanism works. Overall
code size diff is +56 bytes on STM32.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-01 16:21:21 +10:00
..
bare-arm bare-arm/mpconfigport.h: Disable remaining optional features. 2021-11-01 14:23:06 +11:00
cc3200 all: Fix cases of Python variable assigned but never used. 2023-05-02 16:36:05 +10:00
embed embed: Fix arguments to mp_raw_code_load_mem. 2023-03-13 12:35:12 +11:00
esp32 ports: Enable os.sync() for esp32, esp8266, rp2, mimxrt, samd51. 2023-06-01 11:39:01 +10:00
esp8266 ports: Enable os.sync() for esp32, esp8266, rp2, mimxrt, samd51. 2023-06-01 11:39:01 +10:00
mimxrt mimxrt/Makefile: Use a specific fsl_flexspi_nor_boot.c for mimxrt1062. 2023-06-01 12:38:17 +10:00
minimal all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
nrf extmod/machine_pwm: Remove PWM_INIT and PWM_DUTY_U16_NS config options. 2023-05-04 13:19:19 +10:00
pic16bit ports: Implement simple write polling for stdout. 2023-03-23 13:51:17 +11:00
powerpc all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
qemu-arm shared/runtime/gchelper: Drop cpu directive from ARM asm helpers. 2023-01-28 15:51:38 +11:00
renesas-ra renesas-ra/boards/make-pins.py: Fix PA/PB pins support. 2023-06-01 13:00:24 +10:00
rp2 ports: Enable os.sync() for esp32, esp8266, rp2, mimxrt, samd51. 2023-06-01 11:39:01 +10:00
samd ports: Enable os.sync() for esp32, esp8266, rp2, mimxrt, samd51. 2023-06-01 11:39:01 +10:00
stm32 ports: Remove os.sync() implementation from stm32 and renesas-ra. 2023-06-01 11:39:01 +10:00
teensy all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
unix py/builtinimport: Optimise sub-package loading. 2023-06-01 16:21:21 +10:00
webassembly webassembly/modutime: Use extmod version of time module. 2023-04-27 15:11:52 +10:00
windows windows/Makefile: Allow variants to add QSTR_DEFS. 2023-05-11 14:34:15 +10:00
zephyr zephyr/modutime: Use extmod version of time module. 2023-04-27 15:11:52 +10:00