Consider pre-compiling python code in distribution packages or during installation
Python tends to save the pre-compiled Python bytecode to .pyc files while executing a script for performance reasons.
This has several implications (at least in our Windows packages):
- Typically Python does not have write access to the installation folder, so if they're not present at install time, it will never create them, which could reduce performance.
- If we ship outdated ones it's even worse, as Python tries to read them each time only to find they're outdated.
- If we don't ship them, but Python creates them at some point (i.e. while running Inkscape with administrative privileges), we have troubles with our uninstallers (see for example inbox#556 (closed)) as they assume files not previously installed were added by the user and are not safe to delete.
Possible solutions:
- We could ship up-to-date .pyc files - but will they be considered up-to-date on the users system?
- We could create up-to-date .pyc files during installation. This is how Python itself does it. Obviously this requires some effort, would need to be done for each distribution format separately, is fragile (additional code that runs on systems we don't control), and increases install times for users.
- We could ignore the issue and make sure uninstallers delete them / installers warn about them.
Open questions that block a decision (help in investigating those is more than welcome)
-
Are .pyc files useful, i.e. do they actually decrease load times significantly? Do we have numbers? -
How does Python determine whether a .pyc file is up-to-date? If we create them on one system, do they stay valid on another? -
Are there safe/established ways to pre-compile to python bytecode (how does Python itself do it for example?) and how hard would it be to add this to our own installers)
Edited by Jonathan Neuhauser