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
Does it take forever to start a python3 program on an ev3 for anyone else? It takes more than 30s for me to start any program for controlling a robot. Even hello world is taking 6+ seconds.
robot@ev3dev[~]# cat hello_world.py
#!/usr/bin/env python3
print("hello world")
robot@ev3dev[~]#
robot@ev3dev[~]# python3 --version
Python 3.4.2
robot@ev3dev[~]#
robot@ev3dev[~]# time ./hello_world.py
hello world
real 0m6.497s
user 0m2.030s
sys 0m0.340s
robot@ev3dev[~]#
I'm seeing slightly faster times (four to five seconds for the same test you showed) but either way it is slower than would be ideal.
Some additional testing: adding m = LargeMotor() and the appropriate import increased the time to around ten seconds, whereas adding just the import barely affected it, so it looks like actually doing something of use also increased the time significantly. A second initialization of a LargeMotor did not increase the time.
I ran it a few more times and got between 3s and 4s each time, I'm not sure what happened with the 6s run. I changed it to:
robot@ev3dev[~]# cat hello_world.py
#!/usr/bin/env python3
from ev3dev.auto import LargeMotor
m = LargeMotor()
print("hello world")
robot@ev3dev[~]#
robot@ev3dev[~]# time ./hello_world.py
hello world
real 0m48.315s
user 0m30.220s
sys 0m2.170s
robot@ev3dev[~]#
It took 48 seconds!! :( @WasabiFan what do you have for 'python --version'?
Profiling shows that we are spending a huge amount of time importing PIL
Hmmm... I still can't replicate the 30-second-plus ones. I performed the exact same test (with the same Python 3 version) and I get 9-10 seconds. So, I suspect that whatever is taking a long time while importing PIL is not happening on my end, because my normal times are the same as those that you get when you rearrange the import.
I must have done something odd to PIL on my install at some point. I checked in some small changes. I didn't spot anything else obvious to fix to speed this up.
I´ve tried this using py_compile - package loading my_script.py as filename.
It runs but is as slow as before.
What exactly is the hack?
My current testing cycles of the code are way too long so this would really help to get things ready faster.
thx. is the actual code inside the variable code or inside filename.
which package delivers the "compile"-function? currently i cant sort it out. sorry if i missed something obvious... i´m just getting started into that stuff.
Python3 still runs slow and I tried the 'exec' hack (but it doesn't seem to help).
I also tried to manually compile my .py files to .pyc using python3 -m compileall .
It ran with no errors but no .pyc files were created. I have the feeling that the interim bytecode version isn't stored and thus making it very slow to run the programs each time.
Can anyone with more knowledge about this please post? Thanks
Hi @dwalton76 , great hint. However I'm failing importing ev3dev or (preferred) ev3dev2. Apparently micropython uses a different path than python3, hence micropython cannot find the ev3dev libraries. I guess there's a trick how to make EV3 motors and sensors work with micropython but I can't find it.
Please advise...
We have not actually released proper micropython support yet; the code changes are there but packaging isn't. If you'd like to, it is possible to manually copy the library files where they need to go, but my suggestion is to wait until we have a release with the correct packaging.
Thanks for the quick follow up! Will try manual copy for now. Any estimates when it‘s going to be included in the final packaging? I assume you‘re referring to the integration of ev3dev2, not to the older ev3dev... correct?
Von meinem iPhone gesendet.
Am 25.11.2018 um 22:25 schrieb Kaelin Laundry ***@***.***>:
We have not actually released proper micropython support yet; the code changes are there but packaging isn't. If you'd like to, it is possible to manually copy the library files where they need to go, but my suggestion is to wait until we have a release with the correct packaging.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
Yes, this will only apply to the ev3dev2 module. It'll be whenever I get some time to set up the packaging — hopefully this week/weekend now that I got my packaging VM in a functional state again.
Hi Kaelin,
short update… micropython works like a charme. There’s a notable performance improvement (3-4 more loops)… especially compared to native EV3-G software.
However one thing still causes some headaches… initialisation of Sensors and Motors still takes too much time to make ev3dev2 + python3 usable in competitions (such as WRO).
With Python3 my sample script needs 6s before the interesting part of my code executes… so we’d loose at least 6s until all motors and sensors are initialised and before our robot actually starts doing something!
With Micropython this delay has been decreased to 2s. Much better, but still not competitive enough. Any ideas how this can be fixed or if it can be fixed at all?
Regards
Sascha
On 26. Nov 2018, at 08:57, Kaelin Laundry ***@***.***> wrote:
Yes, this will only apply to the ev3dev2 module. It'll be whenever I get some time to set up the packaging — hopefully this week/weekend now that I got my packaging VM in a functional state again.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#204 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ArPCQ2iVeDzVQxpIRAp2r2J-UTJ8FP1-ks5uy575gaJpZM4KAAbr>.
Another option would be to use one single program in the competition so that you only have to pay that 2s penalty once at the very beginning. You could then use a menu to tell your program which chunk of code to execute next.
Good hint… thanks…. worth a try :-)
I’ve continued to “play” a bit with micropython… can’t get Buttons to work because the import of ev3dev2.button throws an exception.
Do we know which classes are going to supported along with micropython?
Currently only motors and sensors are supported, sadly 😢. Documentation will come along with proper micropython packaging (I'm working on this right now). If button support is important to you, please open an issue about it at https://github.com/ev3dev/ev3dev-lang-python so we can track it. (or, if you're feeling particularly motivated, see if you can make it work yourself and submit a pull request 😄)
Hello @WasabiFan and @Dilbert76 . I', having the same problem of slow import on regular python3. Can you guys help in with the micropython and library instalation on the ev3dev brick ?
Thanks alot
So after Lego released their pybrick micropython version, it appears that the weak spot in python and micropython isn't them running the code, or even really booting up (as much), but rather they each load a significant amount of files. Since we are running off SD cards, this has a very huge impact. I ran across this recently as I was working on building a new Javascript SDK and upon reflection noticed that Lego's version of the API is much faster than the default because they have bundled most of it into a single file. In my Javascript SDK, when I do testing and load lots of files individually, it takes very long on the actual robot (on my desktop it is nearly instant). I wrote a small script to merge all the JS files into a single monolithic file, and it was night and day. I was able to run things as fast as a C or Bash program (about 1 second from pushing start to it executing commands).
Could we get a release that is monolithic (all one file) for Micropython? I bet we could get it to run in under 1 or 2 seconds from start then.
I'd be interested to see benchmarks on our codebase. I'm not immediately sure how to pack Python files together, considering the module system, but if someone could figure out how to set up a test and show comparisons that would be very helpful.
On Sep 22, 2019, at 10:12 AM, Brady P. Merkel ***@***.***> wrote:
I'm especially intrigued by @QuriyKort's single-file ev3fast.py implementation; https://github.com/QuirkyCort/ev3dev-lang-python-fast. See his README for the benchmarks he ran.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
Activity
WasabiFan commentedon Sep 18, 2016
I'm seeing slightly faster times (four to five seconds for the same test you showed) but either way it is slower than would be ideal.
Some additional testing: adding
m = LargeMotor()and the appropriate import increased the time to around ten seconds, whereas adding just the import barely affected it, so it looks like actually doing something of use also increased the time significantly. A second initialization of aLargeMotordid not increase the time.dwalton76 commentedon Sep 18, 2016
I ran it a few more times and got between 3s and 4s each time, I'm not sure what happened with the 6s run. I changed it to:
It took 48 seconds!! :( @WasabiFan what do you have for 'python --version'?
Profiling shows that we are spending a huge amount of time importing PIL
If I only import PIL in the Screen init my hello_world drops to 11s
WasabiFan commentedon Sep 19, 2016
Hmmm... I still can't replicate the 30-second-plus ones. I performed the exact same test (with the same Python 3 version) and I get 9-10 seconds. So, I suspect that whatever is taking a long time while importing PIL is not happening on my end, because my normal times are the same as those that you get when you rearrange the import.
dwalton76 commentedon Sep 20, 2016
I must have done something odd to PIL on my install at some point. I checked in some small changes. I didn't spot anything else obvious to fix to speed this up.
WasabiFan commentedon Sep 20, 2016
Ok, sounds good. Glad we got it sorted out! And that import optimization that you made will be good regardless the exact time it took.
codeNinjaDev commentedon Jan 12, 2018
Is there a way to speed this up because I am using this at a timed competition.
ensonic commentedon Jan 12, 2018
@codeNinjaDev you can use a hack like I am using here: https://github.com/OpenRoberta/robertalab-ev3dev/blob/develop/roberta/lab.py#L276
Slidr666 commentedon Jan 18, 2018
Hi ensonic
am i right the important lines are:
[...]
compiled_code = compile(code, filename, 'exec') exec(compiled_code, scope)[...]
I´ve tried this using py_compile - package loading my_script.py as filename.
It runs but is as slow as before.
What exactly is the hack?
My current testing cycles of the code are way too long so this would really help to get things ready faster.
Thanks!
ensonic commentedon Jan 18, 2018
The hack is to pre-start a python program and then use the:
to start the program from that process.
Slidr666 commentedon Jan 18, 2018
thx. is the actual code inside the variable code or inside filename.
which package delivers the "compile"-function? currently i cant sort it out. sorry if i missed something obvious... i´m just getting started into that stuff.
ensonic commentedon Jan 19, 2018
The ticket is probably not the right place to discuss. Lets try the chat-room: https://gitter.im/ev3dev/chat
Atzingen commentedon Sep 21, 2018
hello @ensonic how do you "compile" your python script ? Are you using regular python3.6 or Cython ?
Atzingen commentedon Sep 21, 2018
Can you elaborate more on how do to do this ?
scprotz commentedon Oct 26, 2018
Python3 still runs slow and I tried the 'exec' hack (but it doesn't seem to help).
I also tried to manually compile my .py files to .pyc using python3 -m compileall .
It ran with no errors but no .pyc files were created. I have the feeling that the interim bytecode version isn't stored and thus making it very slow to run the programs each time.
Can anyone with more knowledge about this please post? Thanks
4 remaining items
Dilbert76 commentedon Nov 25, 2018
Hi @dwalton76 , great hint. However I'm failing importing ev3dev or (preferred) ev3dev2. Apparently micropython uses a different path than python3, hence micropython cannot find the ev3dev libraries. I guess there's a trick how to make EV3 motors and sensors work with micropython but I can't find it.
Please advise...
WasabiFan commentedon Nov 25, 2018
We have not actually released proper micropython support yet; the code changes are there but packaging isn't. If you'd like to, it is possible to manually copy the library files where they need to go, but my suggestion is to wait until we have a release with the correct packaging.
Dilbert76 commentedon Nov 26, 2018
WasabiFan commentedon Nov 26, 2018
Yes, this will only apply to the ev3dev2 module. It'll be whenever I get some time to set up the packaging — hopefully this week/weekend now that I got my packaging VM in a functional state again.
Dilbert76 commentedon Nov 27, 2018
dwalton76 commentedon Nov 27, 2018
David figured out a way to overclock the CPU, that might be worth trying:
https://lechnology.com/2018/06/overclocking-lego-mindstorms-ev3-part-2/
Another option would be to use one single program in the competition so that you only have to pay that 2s penalty once at the very beginning. You could then use a menu to tell your program which chunk of code to execute next.
Dilbert76 commentedon Nov 29, 2018
WasabiFan commentedon Nov 29, 2018
Currently only motors and sensors are supported, sadly 😢. Documentation will come along with proper micropython packaging (I'm working on this right now). If button support is important to you, please open an issue about it at https://github.com/ev3dev/ev3dev-lang-python so we can track it. (or, if you're feeling particularly motivated, see if you can make it work yourself and submit a pull request 😄)
Atzingen commentedon Feb 20, 2019
Hello @WasabiFan and @Dilbert76 . I', having the same problem of slow import on regular python3. Can you guys help in with the micropython and library instalation on the ev3dev brick ?
Thanks alot
WasabiFan commentedon Feb 20, 2019
Try
sudo apt install micropython-ev3dev2. I haven't gotten official instructions written yet but that should be the main thing you need to do.fractal13 commentedon Mar 21, 2019
My timing tests show about 3-4 seconds for python3 to start, and an additional 8-9 seconds for the following imports:
import ev3dev2.sensor.lego
import ev3dev2.display
import ev3dev2.fonts
import ev3dev2.motor
scprotz commentedon Sep 22, 2019
So after Lego released their pybrick micropython version, it appears that the weak spot in python and micropython isn't them running the code, or even really booting up (as much), but rather they each load a significant amount of files. Since we are running off SD cards, this has a very huge impact. I ran across this recently as I was working on building a new Javascript SDK and upon reflection noticed that Lego's version of the API is much faster than the default because they have bundled most of it into a single file. In my Javascript SDK, when I do testing and load lots of files individually, it takes very long on the actual robot (on my desktop it is nearly instant). I wrote a small script to merge all the JS files into a single monolithic file, and it was night and day. I was able to run things as fast as a C or Bash program (about 1 second from pushing start to it executing commands).
Could we get a release that is monolithic (all one file) for Micropython? I bet we could get it to run in under 1 or 2 seconds from start then.
WasabiFan commentedon Sep 22, 2019
I'd be interested to see benchmarks on our codebase. I'm not immediately sure how to pack Python files together, considering the module system, but if someone could figure out how to set up a test and show comparisons that would be very helpful.
bpmerkel commentedon Sep 22, 2019
I'm especially intrigued by @QuriyKort's single-file ev3fast.py implementation; https://github.com/QuirkyCort/ev3dev-lang-python-fast. See his README for the benchmarks he ran.
scprotz commentedon Sep 22, 2019