Skip to content

compile python files to reduce program startup time#1426

Open
Houston4444 wants to merge 1 commit intofalkTX:mainfrom
Houston4444:compile_python
Open

compile python files to reduce program startup time#1426
Houston4444 wants to merge 1 commit intofalkTX:mainfrom
Houston4444:compile_python

Conversation

@Houston4444
Copy link

Hi.
The idea is to compile .pyc files in pycache at make install.

This reduce the startup duration of carla. When a python file is imported, python compiles this file in pycache/file.pyc . If this file already exists and matches perfecty with the python file version, then, python uses the compiled file. If we don't install theses compiled files, compilation is done at each startup because the dir is read only.

for comparaison, see the return without pycache of time carla --version

time carla --version
Using Carla version 2.3.0
  Python version: 3.7.3
  Qt version:     5.11.3
  PyQt version:   5.11.3
  Binary dir:     /usr/local/lib/carla
  Resources dir:  /usr/local/share/carla/resources

real    0m0,707s
user    0m0,605s
sys     0m0,082s

and with pycache:

Using Carla version 2.3.0
  Python version: 3.7.3
  Qt version:     5.11.3
  PyQt version:   5.11.3
  Binary dir:     /usr/local/lib/carla
  Resources dir:  /usr/local/share/carla/resources

real    0m0,426s
user    0m0,360s
sys     0m0,049s

Note that the compilation is done at install, and not at make, else when files are moved, compiled files are not considered as matching with python files. It means that python checks if it matches with absolute paths.

@Houston4444
Copy link
Author

I think the checks fails because this PR makes python3 as a new build dependency, but I don't know how to fix this.

@edumco
Copy link
Contributor

edumco commented Aug 12, 2021

Try add python to the .travis.yml

python:

  • "3.8"

@falkTX
Copy link
Owner

falkTX commented Aug 12, 2021

Travis is dead. I am in the process of updating carla to github actions, not finished.

@edumco
Copy link
Contributor

edumco commented Aug 12, 2021

@falkTX great to hear about Actions,

How this python dependency could be solved?

Can we make it call any python version?

@edumco
Copy link
Contributor

edumco commented Aug 12, 2021

@Houston4444 would be nice to have a benchmark showing the time gained in milliseconds and as percentage

@falkTX
Copy link
Owner

falkTX commented Aug 12, 2021

it needs to be python3 for sure, but detection for python is needed. so such block would be inside a check for frontend

@falkTX
Copy link
Owner

falkTX commented Aug 12, 2021

note that this is purely a startup optimization.
runtime remains unaffected afaik.

@edumco
Copy link
Contributor

edumco commented Aug 12, 2021

@falkTX thats why i asked for some benchmark, so you could evaluate the ROI

@falkTX
Copy link
Owner

falkTX commented Aug 13, 2021

Isnt that what @Houston4444 did on the very first post?

anyway, this is a very minor optimization and one that can easily break due to packaging differences in distros.
the python3 executable is not guaranteed to be the same version used for pyuic/pyrcc tools

@Houston4444
Copy link
Author

anyway, this is a very minor optimization and one that can easily break due to packaging differences in distros.
the python3 executable is not guaranteed to be the same version used for pyuic/pyrcc tools

Minor, yes, but appreciable. There is probably a way to use it if it works and not care if it doesn't.

@heruki
Copy link

heruki commented May 6, 2025

@Houston4444 I think it makes sense to have it in the github workflows... it's already there by now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants