You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] pybricksdev is very slow to run a script of 200 lines #283
Describe the bug
Coming from #282, I measured the time for BLEPUPConnection.run(script, wait=False) to complete to be close to 10 seconds. This seems excessive for the task. Running the same script using Pybricks Code takes on average 2-3 seconds for me.
To reproduce
Run the following script for a PoweredUp City hub:
importtimeimportasynciofrompybricksdev.connectionsimportBLEPUPConnectionfrompybricksdev.bleimportfind_deviceasyncdefmain_coro():
device=awaitfind_device("Pybricks Hub")
hub=BLEPUPConnection()
awaithub.connect(device)
t0=time.time()
awaithub.run("autonomous_train.py", wait=False)
t=time.time()-t0print(f"starting program took {t} seconds!")
asyncio.run(main_coro())
The output gives me:
Searching for Pybricks Hub
Connecting to 90:84:2B:BE:1E:40: Pybricks Hub
Connected successfully!
starting program took 9.359002113342285 seconds!
Expected behavior
Given that running the same script using Pybricks Code takes just about 2-3 seconds, I would expect the process to be as fast using pybricksdev
We are revising the program download process extensively at the moment. Once that is complete, pybricksdev can be updated to match, at which point we could look at the download speed as well.
I have only tried one hub for now and have not benchmarked extensively, but download progress should be much faster now. All waits have been removed, so this might be about as fast as Pybricks Code now.
It has also not been tested in notebooks and with multiple programs yet, so things might be a bit flaky for now. It probably also doesn't work with Move Hub just yet.
I checked out latest master commit, flashed to the most recent build using Pybricks Code, and adapted the above example to PybricksHub. This time, I measured a running time of just over 6 seconds. That's a great improvement!
I wanted to test running the same script using Pybricks Code now, but it doesn't seem to work with this firmware yet, I'm getting Incompatible .mpy file in the Pybricks Code console right after connecting, and the run button is greyed out even when connected to the hub. Same when only loading a hello world script. However, running on another hub with older firmware using Pybricks Code also takes about 6 second when manually timing it. So the run time from pybricks code seems to be matched now! In my original post, I might have underestimated the time for Pybricks Code to run the script.
I will need to update my scripts for any changed pybricks API now, as it seems to quit immediately now. (I need to work on making any errors show up for me)
Hopefully we will update https://code.pybricks.com within the next week, but if you are really anxious, you can build and run Pybricks Code locally (instructions are in the GitHub repo with the source code).
@dlech No, for testing the pybricksdev download speed I actually used the same method of timing it as outlined in the first post of this issue. (Though now with the new PybricksHub class instead of BLEPUPConnection)
I just tested again using the updated pybricks code app and measured around 5.5 seconds for a program that I adapted to the new firmware. I timed it after having connected to the hub, from clicking on the run button on pybricks code until "Running downloaded program..." is printed.
The program I am downloading (though that should probably not matter at all): https://pastebin.com/snvpWVU5
I will probably test it on my laptop soon as well.
As a comparison, I also measured the time it takes to flash the firmware. I started the measurement when the progress bar in pybricks code shows up and stopped when it is complete. Came out as 73 seconds. I had the "Include current program" option enabled. I also measured without "Include current program" and the time was 70 seconds.
I tested the download speed on my Linux Mint install now. I used pybricks code in Chrome.
Interestingly, I pretty consistently measure 4.5 seconds, which is on average 1 second faster than on windows on the same machine.
I also want to note that on both windows and linux, I got the "incompatible .mpy file" error (#290 ) from time to time, which I could only fix by restarting the browser.
Activity
laurensvalk commentedon Mar 28, 2021
We are revising the program download process extensively at the moment. Once that is complete,
pybricksdevcan be updated to match, at which point we could look at the download speed as well.laurensvalk commentedon Mar 31, 2021
Pybricksdev has been updated to match the new download and run process. Just get the latest commit from master.
You'll need the latest firmware to try it.
I have only tried one hub for now and have not benchmarked extensively, but download progress should be much faster now. All waits have been removed, so this might be about as fast as Pybricks Code now.
laurensvalk commentedon Mar 31, 2021
It has also not been tested in notebooks and with multiple programs yet, so things might be a bit flaky for now. It probably also doesn't work with Move Hub just yet.
Feel free to share issues if you run into them.
Novakasa commentedon Apr 1, 2021
Great, thank you!
I checked out latest master commit, flashed to the most recent build using Pybricks Code, and adapted the above example to
PybricksHub. This time, I measured a running time of just over 6 seconds. That's a great improvement!I wanted to test running the same script using Pybricks Code now, but it doesn't seem to work with this firmware yet, I'm getting
Incompatible .mpy filein the Pybricks Code console right after connecting, and the run button is greyed out even when connected to the hub. Same when only loading a hello world script. However, running on another hub with older firmware using Pybricks Code also takes about 6 second when manually timing it. So the run time from pybricks code seems to be matched now! In my original post, I might have underestimated the time for Pybricks Code to run the script.I will need to update my scripts for any changed pybricks API now, as it seems to quit immediately now. (I need to work on making any errors show up for me)
dlech commentedon Apr 1, 2021
Hopefully we will update
https://code.pybricks.comwithin the next week, but if you are really anxious, you can build and run Pybricks Code locally (instructions are in the GitHub repo with the source code).dlech commentedon Apr 9, 2021
I assume this includes connecting, running and disconnecting the hub. If you just connect once and stay connected, running should be much faster.
Novakasa commentedon Apr 10, 2021
@dlech No, for testing the pybricksdev download speed I actually used the same method of timing it as outlined in the first post of this issue. (Though now with the new PybricksHub class instead of BLEPUPConnection)
I just tested again using the updated pybricks code app and measured around 5.5 seconds for a program that I adapted to the new firmware. I timed it after having connected to the hub, from clicking on the run button on pybricks code until "Running downloaded program..." is printed.
The program I am downloading (though that should probably not matter at all): https://pastebin.com/snvpWVU5
I will probably test it on my laptop soon as well.
Novakasa commentedon Apr 10, 2021
I just tested with pybricks code on my laptop using it's built in bluetooth adapter, also came out as around 6 seconds.
I tested on both my Desktop PC and on my laptop with Chrome and on Microsoft Edge, in all cases the results were consistent.
Both my machines are Windows 10, but I have also Linux installed, I might try that soon.
Novakasa commentedon Apr 10, 2021
As a comparison, I also measured the time it takes to flash the firmware. I started the measurement when the progress bar in pybricks code shows up and stopped when it is complete. Came out as 73 seconds. I had the "Include current program" option enabled. I also measured without "Include current program" and the time was 70 seconds.
Novakasa commentedon Apr 10, 2021
I tested the download speed on my Linux Mint install now. I used pybricks code in Chrome.
Interestingly, I pretty consistently measure 4.5 seconds, which is on average 1 second faster than on windows on the same machine.
I also want to note that on both windows and linux, I got the "incompatible .mpy file" error (#290 ) from time to time, which I could only fix by restarting the browser.
dlech commentedon Apr 12, 2021
I'm getting similar download times for the pasebin program, so I think we can close this unless pybricksdev is still way slower than Pybricks Code.
Novakasa commentedon Apr 12, 2021
No, the different download times were fixed with last week's changes.
Thanks for the confirmation of the download times!