WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Dedicated extensions for python bytecodes (*.pyc and *.pyo) ?  (Read 185 times)

Offline polikuo

  • Sr. Member
  • ****
  • Posts: 456
Dedicated extensions for python bytecodes (*.pyc and *.pyo) ?
« on: October 14, 2020, 05:32:21 AM »
*.pyc and *.pyo files are compiled bytecodes dynamically created by Python interpreter to speed-up operation. They can be deleted safely and they do not have to be in python-dev.tcz

For people who compile python-related extensions, it's quite common to see *.pyc and *.pyo files floating around all over the place.

These files are compiled machine code for python virtual machine.

FWIK, whenever a python script is called, python would check if (*.pyc exist) and (not older than the original *.py script).

If *.pyc is invalid, python would parse the code and save the result to *.pyc, then run the virtual machine to send instructions to CPU.

When python found a valid *.pyc, python would skip the interpreting.

Thus, the performance boosts.

Anyway, most extensions on the repo drop these files.

I'm wondering if we should make dedicated extensions for these files.

It should theoretically speed up compile time for later extensions.

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 12642
Re: Dedicated extensions for python bytecodes (*.pyc and *.pyo) ?
« Reply #1 on: October 14, 2020, 06:18:44 AM »
I have not noticed any speed difference - *pyc and *pyo files add a lot of bloat and should be removed unless there's a good reason not to.

I've never tried using a separate extension using only *pyc files.

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 667
Re: Dedicated extensions for python bytecodes (*.pyc and *.pyo) ?
« Reply #2 on: October 14, 2020, 07:45:20 AM »
Speed would only be a little change on first execution.   But I think any speed difference is offset by the amount of extra time it would take to make the symlinks when mounting the extension.

Symlinking all of the files in the squashfs to the ramdisk is typically what takes the most amount of time when loading an extension.