Repository navigation
perf(docker): precompile Python bytecode in worker images - #114
Merged
Merged
Conversation
uv pip install does not compile bytecode by default, so the published images ship with no .pyc for runpod, aiohttp, or the worker source. Every fresh container recompiles each imported module on first import, on every cold start. - Pass --compile-bytecode to the build-time uv pip install in all four Dockerfiles (flag, not UV_COMPILE_BYTECODE env, so runtime installs in dependency_installer.py stay uncompiled) - compileall the worker source in /app - Cold-container import runpod.serverless: ~1180ms -> ~600ms (arm64 CPU image, local build); image +10.8MB SLS-809
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The consistent, build-only changes preserve interpreter selection and runtime installation behavior, with no blocking issues identified.
No open issues 🎉
What changed in this PR
Reduces worker cold-start overhead by precompiling Python bytecode during image builds.
Changes:
- Enables dependency bytecode compilation in all four images.
- Precompiles worker source under
/app. - Keeps compilation build-scoped without changing runtime dependency installs.
| File | Description |
|---|---|
| Dockerfile-lb-cpu | Precompiles dependencies and source for CPU load-balanced workers. |
| Dockerfile-lb | Precompiles dependencies and source for GPU load-balanced workers. |
| Dockerfile-cpu | Precompiles dependencies and source for CPU queue-based workers. |
| Dockerfile | Precompiles dependencies and source for GPU queue-based workers. |
Review effort: Balanced
jasonwang-runpod
approved these changes
Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
uv pip installdoes not compile bytecode by default. The publishedrunpod/flash-cpu:latestships with zero.pycforrunpodandaiohttp, so every fresh container recompiles each imported module on first import, on every cold start.--compile-bytecodeon the build-timeuv pip installin all four Dockerfilespython -m compileall -q .for the worker source in/appENV UV_COMPILE_BYTECODE=1: an env var would leak into runtime installs independency_installer.py, where compiling whole packages at boot would add to cold startImpact (arm64 CPU image, local builds, main vs this branch)
.pycrunpod / aiohttpimport runpod.serverless(6 fresh containers)Image ships runpod 1.10.1; absolute numbers drop further once the worker moves to runpod 2.0 (lazy imports).
Test plan
Dockerfile-cpulocally; verified.pycpresent and measured cold-container import before/afterNote for local testing on Apple M4-class Macs: arm64 images SIGILL in
cryptography(OpenSSL SME detection inside the Docker VM) on main as well; run with-e OPENSSL_armcap=0.Linear: SLS-809 (related: SLS-808)