Skip to content

docs: Document @micropython.native usage policy.#406

Merged
nedseb merged 3 commits intomainfrom
docs/micropython-native-policy
Apr 17, 2026
Merged

docs: Document @micropython.native usage policy.#406
nedseb merged 3 commits intomainfrom
docs/micropython-native-policy

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Apr 17, 2026

Summary

Closes #405.

  • Add a guideline to CONTRIBUTING.md (coding conventions): @micropython.native is forbidden in driver code, accepted case-by-case in examples on rendering hot-paths.
  • Remove the unnecessary @micropython.native from compute_display() in radar_screen.py — 3 comparisons, no loop, no measurable benefit. Also remove the now-unused import micropython.

Policy

Context @micropython.native
Driver code (device.py) Never — I2C/SPI bus time dominates
Examples with tight pixel/math loops Accepted if speedup is measurable
Examples with few comparisons / I/O Not useful, do not apply

Test plan

  • make lint passes
  • radar_screen.py still runs correctly without the decorator (the function is identical, just interpreted as bytecode instead of native)

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`.
Copilot AI review requested due to automatic review settings April 17, 2026 04:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Documents a project-wide policy for when @micropython.native should (and should not) be used, and removes an unnecessary usage from a VL53L1X example to align with that policy.

Changes:

  • Add a CONTRIBUTING.md guideline discouraging @micropython.native in drivers and clarifying when it’s acceptable in examples.
  • Remove @micropython.native (and the now-unused import micropython) from compute_display() in radar_screen.py.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/vl53l1x/examples/radar_screen.py Removes unused micropython import and drops @micropython.native from a non-hot-path helper.
CONTRIBUTING.md Adds a coding-conventions bullet documenting the @micropython.native usage policy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

nedseb added 2 commits April 17, 2026 06:30
Apply the policy documented in this PR to the three examples with
tight pixel loops:

- tamagotchi.py: draw_character() — 4 nested loops, pixel by pixel
- spirit_level.py: fill_circle() — double loop with x*x + y*y test
- maze_game.py: draw_maze() — double loop over 11x11 grid
…ple.

draw_cube() runs 12 math.sin/cos calls + floating-point arithmetic per
frame in a tight animation loop. Native compilation reduces the per-frame
overhead significantly on the STM32WB55.
@nedseb nedseb merged commit c8375a6 into main Apr 17, 2026
9 checks passed
@nedseb nedseb deleted the docs/micropython-native-policy branch April 17, 2026 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: Document @micropython.native usage policy.

2 participants