pyboard.py very slow on windows, reason and solution
I have recently adopted my µPIDE Micropython IDE to use pyboard.py for remote communication. I soon noticed that transfers from the device to the host are 5 times slower under Windows 10 than under Linux. My previous own version did not have such an issue,
It turned out that serial.inWaiting() is awfully slow on Windows 10 and it's being called for every single byte that's being read via read_until().
As a solution I wrote a little buffering serial wrapper.
https://github.com/harbaum/upide/blob/main/src/buffered_serial.py
This can be used in pyboard.py like import buffered_serial as serial in https://github.com/micropython/micropython/blob/0a217624e1d26899986d3e79eb604652da540b00/tools/pyboard.py#L268
This avoids calling inWaiting() permanently and as a result pyboard.py's read performance now feels similar to Linux.
P.S.: This is not yet included in a µPIDE release, so the latest v1.1.0 still shows that slowness.
tools/pyboard.py: Port recent patchs from mpremote serial transport, to add timeouts for non-responsive serial ports
Summary
This applies #16513 and #16616 (made for mpremote) to tools/pyboard.py. They add timeouts to the initial connection phase to a target board, to help with non-responsive serial ports. Without these patches pyboard.py can hang indefinitely waiting for a board to respond.
Testing
To be tested by @hmaerki on Octoprobe.
Trade-offs and Alternatives
The test runners still use pyboard.py. Eventually it would be good to change them to use mpremote as the backend, but that's a lot more effort.