Replace poll-sleep loop in send_command with blocking read#29
Merged
Replace poll-sleep loop in send_command with blocking read#29
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 duringmd.boutput. 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
c22e83d0== devicec22e83d0🤖 Generated with Claude Code