diff --git a/Dockerfile b/Dockerfile index ef0d4ad..07782ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,8 +71,11 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-ins # Use --python to target the active interpreter (preserves torch in its site-packages) COPY README.md pyproject.toml uv.lock ./ COPY src/ ./ +# Precompile bytecode at build time: a fresh container otherwise recompiles +# every imported module on first import, on every cold start. RUN uv export --format requirements-txt --no-dev --no-hashes > requirements.txt \ - && uv pip install --python $(which python) --break-system-packages -r requirements.txt + && uv pip install --compile-bytecode --python $(which python) --break-system-packages -r requirements.txt \ + && python -m compileall -q . # Install numpy for the active Python version. # The runpod/pytorch image ships torch but not numpy. Flash build excludes numpy diff --git a/Dockerfile-cpu b/Dockerfile-cpu index 48c174f..7ed3d8f 100644 --- a/Dockerfile-cpu +++ b/Dockerfile-cpu @@ -32,7 +32,10 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-ins # Copy app code and install dependencies COPY README.md pyproject.toml uv.lock ./ COPY src/ ./ +# Precompile bytecode at build time: a fresh container otherwise recompiles +# every imported module on first import, on every cold start. RUN uv export --format requirements-txt --no-dev --no-hashes > requirements.txt \ - && uv pip install --system --break-system-packages -r requirements.txt + && uv pip install --compile-bytecode --system --break-system-packages -r requirements.txt \ + && python -m compileall -q . CMD ["python", "handler.py"] diff --git a/Dockerfile-lb b/Dockerfile-lb index ff927c6..7d04f4e 100644 --- a/Dockerfile-lb +++ b/Dockerfile-lb @@ -66,8 +66,11 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-ins # Use --python to target the active interpreter (preserves torch in its site-packages) COPY README.md pyproject.toml uv.lock ./ COPY src/ ./ +# Precompile bytecode at build time: a fresh container otherwise recompiles +# every imported module on first import, on every cold start. RUN uv export --format requirements-txt --no-dev --no-hashes > requirements.txt \ - && uv pip install --python $(which python) --break-system-packages -r requirements.txt + && uv pip install --compile-bytecode --python $(which python) --break-system-packages -r requirements.txt \ + && python -m compileall -q . # Install numpy for the active Python version. # The runpod/pytorch image ships torch but not numpy. Flash build excludes numpy diff --git a/Dockerfile-lb-cpu b/Dockerfile-lb-cpu index f99459f..1d0645f 100644 --- a/Dockerfile-lb-cpu +++ b/Dockerfile-lb-cpu @@ -32,8 +32,11 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-ins # Copy app code and install dependencies COPY README.md pyproject.toml uv.lock ./ COPY src/ ./ +# Precompile bytecode at build time: a fresh container otherwise recompiles +# every imported module on first import, on every cold start. RUN uv export --format requirements-txt --no-dev --no-hashes > requirements.txt \ - && uv pip install --system --break-system-packages -r requirements.txt + && uv pip install --compile-bytecode --system --break-system-packages -r requirements.txt \ + && python -m compileall -q . EXPOSE 80