Skip to content

Replace poll-sleep loop in send_command with blocking read#29

Merged
widgetii merged 1 commit intomasterfrom
fix-send-command-polling
Apr 3, 2026
Merged

Replace poll-sleep loop in send_command with blocking read#29
widgetii merged 1 commit intomasterfrom
fix-send-command-polling

Conversation

@widgetii
Copy link
Copy Markdown
Member

@widgetii widgetii commented Apr 3, 2026

Problem

send_command() used a poll-sleep loop: bytes_waiting() → if 0, sleep(0.05) → repeat. Each 50ms sleep wastes time when serial data has small gaps between lines during md.b output. Over 4096 blocks in a 16MB flash dump, this adds up.

Fix

Replace with read(4096, timeout=0.1) which returns immediately when data arrives — no wasted idle time.

Verified

  • Flash dump speed: 1.7 KB/s → 2.0 KB/s (18% improvement)
  • CRC32 match: local c22e83d0 == device c22e83d0
  • Two consecutive reads of same block: identical
  • All 281 tests pass

🤖 Generated with Claude Code

The old loop polled bytes_waiting() and slept 50ms when empty,
wasting up to 50ms per gap in serial data. Replaced with a direct
read(4096, timeout=0.1) that returns as soon as data arrives.

Flash dump speed: 1.7 KB/s -> 2.0 KB/s (verified correct via
CRC32 match against device, and two identical consecutive reads).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@widgetii widgetii merged commit 3fcfff6 into master Apr 3, 2026
13 checks passed
@widgetii widgetii deleted the fix-send-command-polling branch April 3, 2026 11:57
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.

1 participant