Compile bytecode into the image (boot-time health check misses) #136

Merged
CrowderSoup merged 1 commit from claude/precompile-bytecode into main 2026-11-24 21:12:27 +00:00
Owner

The first deploy of #135 failed its health check. Pyroscope's profile of that container explains why: each gunicorn worker spent about 12 s of CPU compiling Python source at boot, because the image has no .pyc files and PYTHONDONTWRITEBYTECODE keeps them from being written. That boot ran while vPages was building on the droplet, and it missed kamal-proxy's 30 s limit. The re-run succeeded once the droplet was quiet.

This compiles the venv and the app at build time with compileall. Locally, importing the app drops from 1.8 s to 0.9 s, and the image built from a clean git archive has 4,256 .pyc files.

🤖 Generated with Claude Code

The first deploy of #135 failed its health check. Pyroscope's profile of that container explains why: each gunicorn worker spent about 12 s of CPU compiling Python source at boot, because the image has no `.pyc` files and `PYTHONDONTWRITEBYTECODE` keeps them from being written. That boot ran while vPages was building on the droplet, and it missed kamal-proxy's 30 s limit. The re-run succeeded once the droplet was quiet. This compiles the venv and the app at build time with `compileall`. Locally, importing the app drops from 1.8 s to 0.9 s, and the image built from a clean `git archive` has 4,256 `.pyc` files. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Compile bytecode into the image
All checks were successful
tests / pytest (push) Successful in 1m16s
3a6e32c985
PYTHONDONTWRITEBYTECODE keeps .pyc from being written at runtime, and the
image had none, so every gunicorn worker compiled Django and all its
dependencies from source at boot. Pyroscope showed ~12 s of CPU per
worker for that on the droplet, enough to miss kamal-proxy's 30 s health
check while another deploy was building there (deploy run 150). Locally
the app import drops from 1.8 s to 0.9 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.