Commit d7ca7d2
Pierre-Luc Tessier Gagne
perf(neovi): avoid exception path on empty receive buffer
Root cause:
`_recv_internal()` relied on catching `IndexError` from `deque.popleft()` when
no frame was available. In polling-heavy workloads, empty reads can be common,
so exception construction/handling becomes an avoidable steady-state cost.
Implemented solution:
- Replace `try/except IndexError` with an explicit `if not self.rx_buffer`
branch after queue processing.
- Keep behavior identical: return `(None, False)` when no message is available.
Rationale vs alternatives:
Branch-based empty checks are cheaper than exception-driven control flow in
normal operation and require minimal code change.
Performance evidence:
Session microbenchmark for empty recv control flow (500,000 iterations):
- exception path: 0.061096s
- branch path: 0.011707s
- speedup: ~5.22x
Test methodology:
- Synthetic `timeit` benchmark comparing empty deque try/except vs pre-check.
- Functional validation in session:
`python -m pytest test/test_neovi.py` -> passed.
Assumptions, limitations, risks:
- Biggest win occurs when the receive loop polls frequently without data.
- If traffic is always dense, relative benefit is lower.
Potential follow-ups:
- Measure in a real notifier/polling deployment with realistic idle/active mix.
Other identified optimizations not implemented in this commit:
- NetworkID cast simplification in send.1 parent 75b7530 commit d7ca7d2
1 file changed
Lines changed: 4 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
460 | 460 | | |
461 | 461 | | |
462 | 462 | | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
| 463 | + | |
467 | 464 | | |
468 | | - | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
469 | 468 | | |
470 | 469 | | |
471 | 470 | | |
| |||
0 commit comments