summaryrefslogtreecommitdiffstats
path: root/src/cephadm
diff options
context:
space:
mode:
authorJohn Mulligan <jmulligan@redhat.com>2023-05-11 20:20:41 +0200
committerJohn Mulligan <jmulligan@redhat.com>2023-05-11 20:28:09 +0200
commit06bed38931846749dba71ecbada5e3fe64b0dae2 (patch)
tree8f9f90c5d2cc178957009881d3a4ee11c80da559 /src/cephadm
parentMerge pull request #51427 from zdover23/wip-doc-2023-05-10-cephfs-fs-volumes-... (diff)
downloadceph-06bed38931846749dba71ecbada5e3fe64b0dae2.tar.xz
ceph-06bed38931846749dba71ecbada5e3fe64b0dae2.zip
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>
Diffstat (limited to 'src/cephadm')
-rwxr-xr-xsrc/cephadm/build.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/cephadm/build.py b/src/cephadm/build.py
index 4e97f5d3757..39c93ce3b30 100755
--- a/src/cephadm/build.py
+++ b/src/cephadm/build.py
@@ -6,6 +6,7 @@
# of python to build with? Even with the intermediate cmake layer?
import argparse
+import compileall
import logging
import os
import pathlib
@@ -67,6 +68,14 @@ def _build(dest, src):
def _compile(dest, tempdir):
"""Compile the zipapp."""
+ log.info("Byte-compiling py to pyc")
+ compileall.compile_dir(
+ tempdir,
+ maxlevels=16,
+ legacy=True,
+ quiet=1,
+ workers=0,
+ )
# TODO we could explicitly pass a python version here
log.info("Constructing the zipapp file")
try: