Skip to content

Commit d698780

Browse files
committed
docs: Add bound method latency results to tracking doc.
Signed-off-by: Andrew Leech <[email protected]>
1 parent b03aecf commit d698780

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

docs/coroutine-implementation.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -724,27 +724,33 @@ TIM2 @ 10MHz (100ns/tick), NUCLEO_H563ZI @ 250MHz.
724724
| Callback Type | Counter Method | Avg Ticks | Avg ns |
725725
|---------------|---------------|-----------|--------|
726726
| **Direct Viper** |
727-
| **Viper direct** | **ptr32** | **16** | **1600** |
727+
| Viper direct | ptr32 | **16** | **1600** |
728728
| **Functions** |
729-
| Bytecode func | t.counter() | 27 | 2700 |
730-
| Bytecode func | mem32[] | 23 | 2300 |
731-
| Bytecode func | viper_read() | 27 | 2700 |
729+
| Bytecode func | t.counter() | 26 | 2600 |
730+
| Bytecode func | mem32[] | 25 | 2500 |
731+
| Bytecode func | viper_read() | 28 | 2800 |
732732
| **Generators** |
733-
| Bytecode gen | t.counter() | 28 | 2800 |
734-
| Native gen | t.counter() | 25 | 2500 |
733+
| Bytecode gen | t.counter() | 27 | 2700 |
734+
| Native gen | t.counter() | 24 | 2400 |
735735
| Bytecode gen | mem32[] | 24 | 2400 |
736-
| Native gen | mem32[] | 21 | 2100 |
736+
| Native gen | mem32[] | **20** | **2000** |
737737
| Bytecode gen | viper_read() | 28 | 2800 |
738+
| **Generic Callables** |
739+
| Bound method | t.counter() | 62 | 6200 |
738740

739741
**Key findings:**
740742

741743
1. **Direct `@viper` callback is fastest** at 16 ticks (1.6µs) - 24% faster than
742744
@native generators. Requires `array.array` + `uctypes.addressof()` for storage
743745
since viper can't access Python lists.
744-
2. **`@native` generator + `mem32[]`** at 21 ticks is fastest for code needing
746+
2. **`@native` generator + `mem32[]`** at 20 ticks is fastest for code needing
745747
Python data structure access.
746748
3. **Calling convention fix was critical** - Previous dispatch used wrong signature
747749
`(mp_obj_t)` instead of `(fun, n_args, n_kw, args)`. Fixed in 76b5665a07.
750+
4. **Bound methods are slowest** at 62 ticks (6.2µs) due to generic dispatch via
751+
`mp_call_function_1()`. The extra ~36 ticks come from type lookups, args array
752+
construction, and multiple function calls through the bound method machinery.
753+
Use plain functions or generators when latency matters.
748754

749755
For absolute minimum latency, use direct `@viper` callback with `ptr32()` and
750756
array-based storage. For easier Python interop, use `@native` generator with

0 commit comments

Comments
 (0)