Enable Python bytecode compilation in UV for faster cold starts#832
Open
Enable Python bytecode compilation in UV for faster cold starts#832
Conversation
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.
|
|
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
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
.pycformat.Key Changes
UV_COMPILE_BYTECODE=1environment variable to the Docker base stageImplementation 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