Skip to content

Enable Python bytecode compilation during build to reduce cold-start time#68

Open
bcherry wants to merge 1 commit intomainfrom
claude/update-starter-dockerfile-rXcxP
Open

Enable Python bytecode compilation during build to reduce cold-start time#68
bcherry wants to merge 1 commit intomainfrom
claude/update-starter-dockerfile-rXcxP

Conversation

@bcherry
Copy link
Copy Markdown
Contributor

@bcherry bcherry commented Apr 29, 2026

Summary

This change enables Python bytecode compilation during the Docker build process to improve agent cold-start performance by pre-compiling Python source files to .pyc format.

Key Changes

  • Added UV_COMPILE_BYTECODE=1 environment variable to the base Docker stage
  • This instructs the uv package manager to compile all Python source code to bytecode during dependency installation

Implementation Details

By pre-compiling Python source to bytecode during the build phase, the first import of Python modules no longer incurs the compilation cost at runtime. This reduces cold-start latency for the agent, though it comes at the trade-off of a slightly longer build time. The bytecode compilation happens once during image build rather than on every container startup.

https://claude.ai/code/session_01Noyea9Jyi7sgN1ctUhpZJf

Add UV_COMPILE_BYTECODE=1 to compile Python source to bytecode during
install. This reduces agent cold-start time at the expense of a slightly
longer build.

Mirrors livekit/web#4070.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants