Commit c8375a6
authored
docs: Document @micropython.native usage policy. (#406)
* 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`.
* perf: Add @micropython.native to rendering hot-paths in examples.
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
* perf(ssd1327): Add @micropython.native to draw_cube() in 3D cube example.
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.1 parent a3ddb36 commit c8375a6
6 files changed
Lines changed: 9 additions & 2 deletions
File tree
- lib
- bq27441/examples
- ism330dl/examples
- ssd1327/examples
- vl53l1x/examples
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
227 | 228 | | |
228 | 229 | | |
229 | 230 | | |
| 231 | + | |
230 | 232 | | |
231 | 233 | | |
232 | 234 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
183 | 184 | | |
184 | 185 | | |
185 | 186 | | |
| 187 | + | |
186 | 188 | | |
187 | 189 | | |
188 | 190 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
32 | | - | |
33 | 31 | | |
34 | 32 | | |
35 | 33 | | |
| |||
0 commit comments