-
Notifications
You must be signed in to change notification settings - Fork 557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance in the Python runtime module #6884
Merged
helderco
merged 6 commits into
dagger:main
from
helderco:helder/dev-3558-improve-performance-with-uv-and-add-basic-configurability-to
Apr 1, 2024
Merged
Improve performance in the Python runtime module #6884
helderco
merged 6 commits into
dagger:main
from
helderco:helder/dev-3558-improve-performance-with-uv-and-add-basic-configurability-to
Apr 1, 2024
Conversation
This file contains 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
helderco
force-pushed
the
helder/dev-3558-improve-performance-with-uv-and-add-basic-configurability-to
branch
from
March 16, 2024 09:39
1cc3fab
to
ece26ac
Compare
helderco
force-pushed
the
helder/dev-3558-improve-performance-with-uv-and-add-basic-configurability-to
branch
from
March 19, 2024 17:06
ece26ac
to
a3159ea
Compare
gerhard
approved these changes
Mar 26, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the PR description - it's world class 🥇🚀
Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
Because of Rye: astral-sh/rye#895 Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
helderco
force-pushed
the
helder/dev-3558-improve-performance-with-uv-and-add-basic-configurability-to
branch
from
March 30, 2024 10:54
a3159ea
to
6ecefa9
Compare
Added missing tests. |
helderco
force-pushed
the
helder/dev-3558-improve-performance-with-uv-and-add-basic-configurability-to
branch
from
March 30, 2024 11:13
6ecefa9
to
1608b08
Compare
helderco
deleted the
helder/dev-3558-improve-performance-with-uv-and-add-basic-configurability-to
branch
April 1, 2024 17:40
This was referenced Apr 3, 2024
vikram-dagger
pushed a commit
to vikram-dagger/dagger
that referenced
this pull request
May 3, 2024
* Improve performance in the Python runtime module Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com> * Fix tests Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com> * Add change log Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com> * Add setting for overriding uv version Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com> * Remove root editable install in requirements.lock file Because of Rye: astral-sh/rye#895 Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com> * Add tests Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com> --------- Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
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.
This PR adds uv support, using it by default to install python packages.
The need for speed
The main motivation is performance. Some quick numbers:
Without uv:
python -m venv
→ ≈2.08spip install -r lock
→ ≈4s (cold)pip install -e sdk
→ ≈6.30s/3.56s (cold/warm)With uv:
uv venv
→ ≈0.03suv pip install -r lock
→ ≈0.9s (cold)uv pip install -e sdk
→ ≈1.36s/0.76s (cold/warm)These were not properly benchmarked, but the speed is real and uv does unlock a few things:
requirements.lock
file ondagger init --sdk=python
by default.--no-deps
is faster.dagger init --sdk=python
!There were other efforts at improving performance beyond uv too:
Codegen
andRuntimeModule
functions to reuse as much layer cache as possible.exec /runtime
step..Entries()
fetch.Configurability
uv is still very new, but it’s already production ready and being adopted in the community like wild fire 🔥. But, in case there’s any conflict or issue, I took the opportunity to introduce configurability into the runtime module. There’s more configurations to come, but for now, these are available:
[tool.dagger]
table inpyproject.toml
to add dagger specific configuration:use-uv = false
to disable uv and use pip instead.uv-version = "==0.1.27"
to override the default pinned uv versionbase-image = "mypython:3.12"
to use a different base image1 (e.g., add system packages, certificates, etc)..python-version
file, as used by pyenv and rye, to use a different Python version:rye pin 3.12
.requirements.lock
file, if exists, will assume it has all dependencies in it.For more advanced use cases, the pipelines have been more granularly composed to allow reusability in a custom SDK module that uses this one as a dependency, in order to customize some part of the process. Without this, you’d had to duplicate most of the code.
Note that adding configurability adds an overhead, but I feel it's necessary. And there's a flag to disable it if doing a custom SDK use case.
Default template
The default template has a couple of changes:
pyproject.toml
:dependencies = []
to make it clearer how to add custom python dependenciessrc/main/__init__.py
instead ofsrc/main.py
.dagger init
should create code from template insrc/main/__init__.py
instead ofsrc/main.py
#6863requirements.lock
file is created, with pinned versions for SDK dependencies at the time that the new module is created.Reproducibility
Summarizing from above, you have stronger guarantees for a reproducible environment, with:
requirements.lock
file.python-version
uv-version
configWhat's next?
There's more follow-up configuration and performance gains but need to do more profiling and tracing will help with that.
Footnotes
Use at own risk since we can’t guarantee support for custom deviations. For best compatibility extend from the default image that dagger uses:
python:3.11-slim
. May need to watch out when the default image is updated. ↩