]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
cephadm: call compile_dir to byte compile zipapp py files 51650/head
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 11 May 2023 18:20:41 +0000 (14:20 -0400)
committerAdam King <adking@redhat.com>
Sun, 21 May 2023 20:22:35 +0000 (16:22 -0400)
commita7aa7975af2ed869393fa52248f8e89d4798ded3
tree795c40a791297223f4ab726b4434c5597f145caa
parentbec53a5f29f0dd7516fd061d4caddf66bc0bf085
cephadm: call compile_dir to byte compile zipapp py files

Python provides the compileall module to explicitly create pyc files
from py files. If we byte-compile the content of the cephadm zipapp
we get a small speed boost when running the application.

In a not-very-scientific benchmark I found that running with pyc files
almost halved the time to run the help command 50 times.

```
$ time for _ in {0..50}; do  /tmp/cephadm-nobc -h >/dev/null; done

real    0m9.486s
user    0m8.547s
sys     0m0.893s

$ time for _ in {0..50}; do  /tmp/cephadm-bc -h >/dev/null; done

real    0m4.634s
user    0m3.992s
sys     0m0.618s
```

I ran the above a few times on my laptop and the numbers are pretty
consistent.

One thing to note is that zipapp doesn't seem to understand the current
`__pycache__` approach to storing the bytecode files so we have to set
the `legacy` argument for compileall.compile_dir to true. Since
__pycache__ dirs mostly exist to allow multiple bytecode files for
different python versions to coexist, and a zipapp is read-only this
should not be a major issue. Tangentially related, we lose out on the
speedup if you run the zipapp with a version of python other than the
one the zipapp was built with but it continues to function.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit 06bed38931846749dba71ecbada5e3fe64b0dae2)
src/cephadm/build.py