Skip to content

Commit 8262532

Browse files
committed
docs: Document @micropython.native usage policy.
Closes #405. Add a guideline to CONTRIBUTING.md: @micropython.native must not be used in driver code (I2C/SPI bus time dominates, native compilation gains nothing) but may be used in examples on rendering hot-paths where a measurable speedup is expected. Remove the unnecessary @micropython.native from compute_display() in radar_screen.py — the function does 3 comparisons with no loop, so native compilation provides no benefit. Also remove the now-unused `import micropython`.
1 parent a3ddb36 commit 8262532

2 files changed

Lines changed: 1 addition & 2 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ lib/<component>/
3535
- **Time**: use `from time import sleep_ms` (not `utime`, not `sleep()` with float seconds).
3636
- **Exceptions**: use `except Exception:` instead of bare `except:`. Enforced by ruff (E722).
3737
- **No debug `print()`** in production driver code. Enforced by ruff (T20, examples and tests excluded).
38+
- **`@micropython.native`**: do **not** use in driver code (`device.py`) — methods are dominated by I2C/SPI bus time, so native compilation gains nothing and reduces debuggability. In **examples**, it may be used on rendering hot-paths (tight pixel loops, math-heavy drawing functions) where a measurable speedup is expected. Do not apply it to functions with only a few comparisons or I/O calls. Note: the native emitter does not support generators, closures, or `with` statements.
3839

3940
## Driver API conventions
4041

lib/vl53l1x/examples/radar_screen.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from time import sleep_ms
99

10-
import micropython
1110
import ssd1327
1211
from machine import I2C, SPI, Pin
1312
from steami_screen import DARK, GRAY, LIGHT, RED, Screen, SSD1327Display
@@ -29,7 +28,6 @@
2928
tof = VL53L1X(i2c)
3029

3130

32-
@micropython.native
3331
def compute_display(distance):
3432
"""Compute proximity and color from distance value.
3533

0 commit comments

Comments
 (0)