ev3dev / ev3dev-lang-python

Pure python bindings for ev3dev
MIT License
422 stars 146 forks source link

Slow Import Speeds - Advice? #775

Closed neelkarma closed 2 years ago

neelkarma commented 2 years ago

Importing modules from the ev3dev2 library takes a very long time - north of 20 seconds in python3 and 10 in micropython. I know it might not seem like much, but we're using ev3dev in a robot competition, in which there is a 2-minute time limit, so those 20 seconds are pretty crucial. Do you all have any tips on how to speed up the import speeds or is it a lost cause?

dlech commented 2 years ago
  1. You can create a "master" program that already gets the Python/MicroPython runtime up and running and waits for a button press before actually moving the robot.
  2. https://pybricks.com/ev3-micropython/ It is not instant, but it has a faster startup time.
  3. You could not use a library and make your own MicroPython code to read/write sysfs files directly and only include exactly what you need and nothing more.
WesleyJ-128 commented 2 years ago

Option 1 suggested by dlech is probably the best. If you want to see an example of a "master program", my code for one is here: https://github.com/WesleyJ-128/FLL_Python_Codebase

neelkarma commented 2 years ago

As for reading/writing sysfs files directly, that's a bit too low-level for us, so I think I'll try a combination of the master program approach and using ev3-micropython instead. Thanks for the tips!