Skip to content

Enable Python bytecode compilation in UV for faster cold starts#832

Open
bcherry wants to merge 1 commit intomainfrom
claude/add-uv-compile-bytecode-pSaW3
Open

Enable Python bytecode compilation in UV for faster cold starts#832
bcherry wants to merge 1 commit intomainfrom
claude/add-uv-compile-bytecode-pSaW3

Conversation

@bcherry
Copy link
Copy Markdown
Contributor

@bcherry bcherry commented Apr 23, 2026

Summary

This change enables Python bytecode compilation during the UV package installation phase to reduce agent cold-start time by pre-compiling Python source files to .pyc format.

Key Changes

  • Added UV_COMPILE_BYTECODE=1 environment variable to the Docker base stage
  • This causes UV to compile all Python source code to bytecode during the build phase rather than at first import

Implementation Details

By pre-compiling Python source to bytecode during the Docker build, the first import of Python modules no longer incurs the compilation cost. This trades a slightly longer build time for significantly faster agent startup, which is beneficial for cold-start scenarios. The change is applied in the base stage so it affects all subsequent build stages.

https://claude.ai/code/session_01UD9HXN6LC1bHa9c8D2EVHN

Added UV_COMPILE_BYTECODE=1 to the base stage of the Python uv Dockerfile
template with explanatory comments about the tradeoff (longer build time
for faster cold-start). Mirrors the docs guidance in livekit/web#4070.
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

3 participants