Skip to content

Add --compile-bytecode flag to uv pip install commands for faster container startup #1694

@coderabbitai

Description

@coderabbitai

https://docs.astral.sh/uv/reference/cli/#uv-pip-install--compile-bytecode

Problem Description

Container startup performance is significantly degraded due to missing --compile-bytecode flag in uv pip install commands across all Dockerfiles. This causes Python modules to compile bytecode at runtime during container startup instead of pre-compiling during the Docker build phase.

Impact

  • CI Test Failures: Containers repeatedly fail Kubernetes readiness/liveness probes with connection refused errors
  • Slow Startup: Container startup hangs during jupyter elyra --generate-config due to slow Python module imports
  • Non-deterministic Performance: Startup times vary significantly depending on runtime compilation overhead
  • User Experience: Poor container startup reliability in production environments

Root Cause Analysis

Python modules without pre-compiled bytecode (.pyc files) trigger on-the-fly compilation during import, causing:

  1. Significant startup delays when importing many modules (common in Jupyter environments)
  2. Kubernetes probe timeouts (typically 5-10 seconds) being exceeded
  3. Container restart loops in orchestrated environments

Affected Scope

35 Dockerfiles across the entire notebook ecosystem are affected:

Image Types:

  • codeserver: ubi9-python-3.11, ubi9-python-3.12 (CPU variants)
  • jupyter: datascience, minimal, pytorch, tensorflow, trustyai (CPU, CUDA, ROCm variants for both Python 3.11 and 3.12)
  • runtimes: datascience, minimal, pytorch, tensorflow, rocm-pytorch, rocm-tensorflow (CPU, CUDA, ROCm variants)
  • rstudio: c9s-python-3.11, rhel9-python-3.11 (CPU, CUDA variants)

Current Problematic Pattern:

uv pip install --strict --no-deps --no-cache --no-config --no-progress --verify-hashes --index-strategy=unsafe-best-match --requirements=./requirements.txt --build-constraints=./requirements.txt

Solution

Add --compile-bytecode flag to all uv pip install commands:

uv pip install --compile-bytecode --strict --no-deps --no-cache --no-config --no-progress --verify-hashes --index-strategy=unsafe-best-match --requirements=./requirements.txt --build-constraints=./requirements.txt

Benefits:

  1. Pre-compiled Bytecode: .pyc files generated during Docker build, not at runtime
  2. Faster Startup: Eliminates compilation overhead during container initialization
  3. Deterministic Performance: Consistent startup times across deployments
  4. Probe Reliability: Containers become ready within Kubernetes timeout windows
  5. Better UX: Reliable container startup in production environments

Implementation Approach

  1. Systematic Update: Add --compile-bytecode flag to all 35 affected Dockerfiles
  2. Consistent Placement: Position flag consistently (after --compile-bytecode before other flags)
  3. Verification Testing: Ensure CI tests pass with improved startup performance
  4. Performance Validation: Measure startup time improvements

Acceptance Criteria

Core Requirements:

  • All 35 Dockerfiles updated with --compile-bytecode flag
  • Flag positioned consistently in command structure
  • No regression in package installation functionality
  • CI tests pass without probe timeout failures

Verification Steps:

  • Container startup time measurements show improvement
  • Kubernetes readiness/liveness probes succeed consistently
  • Python module imports complete faster at runtime
  • No build failures or dependency resolution issues

Testing Coverage:

  • All affected image types (codeserver, jupyter, runtimes, rstudio)
  • Both Python 3.11 and 3.12 variants
  • CPU, CUDA, and ROCm accelerator configurations
  • Cross-platform compatibility (amd64, arm64)

Context Links

Related Documentation

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

✅Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions