wendlers / mpfshell

A simple shell based file explorer for ESP8266 Micropython based devices ⛺
MIT License
396 stars 84 forks source link

Performance improvement: Will not call sleep() at the last cycle. #89

Closed hmaerki closed 4 years ago

hmaerki commented 4 years ago

Hi Wendlers When doing massive communications, this Pull Request improves performance heavily. Thanks, Hans

skorokithakis commented 4 years ago

Thanks for this! Can you add a comment to explain why you're doing what you're doing, and how it speeds things up? It seems to me that this only shaves off 0.01 sec from the last command.

hmaerki commented 4 years ago

Thanks for this! Can you add a comment to explain why you're doing what you're doing, and how it speeds things up? It seems to me that this only shaves off 0.01 sec from the last command.

Hi Stavros I use mpfshell heavily in automating communication between pc and pyboard. This automation does not use the interactive shell but directly the underlying MpFileExplorer and MpFileShell. I very much like the layering of mpfshell as it allows me to directly access the functionality I need. Communication to the pyboard over a serial line takes around 2ms. Optimizing 10ms away is a immense improvement:-)

skorokithakis commented 4 years ago

Oh I see, so you call this in a loop? Maybe there's some other way to do it so that we can remove the sleep altogether and wait for the data to be received instead?

hmaerki commented 4 years ago

Oh I see, so you call this in a loop? Maybe there's some other way to do it so that we can remove the sleep altogether and wait for the data to be received instead?

Good hint to remove the sleep!

Using read_until() instead of read() works fine for me.

self.con.write(command_bytes)
self.con.write(b"\x04")

# check if we could exec command
data = self.read_until(2, b"OK", timeout=0.5)
if data != b"OK":
    raise PyboardError("could not exec command")
skorokithakis commented 4 years ago

Hmm, does the board return OK for every command, including file transfers etc? I'm not sure we can safely do this, though we may be able to.