Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,27 @@ jobs:
- name: "Extract artifact archive"
run: tar -xvf benchmarks-walltime.tar

- name: "Install system dependencies"
run: |
sudo apt-get update
sudo apt-get install -y libsasl2-dev libldap2-dev libkrb5-dev

- name: "Clone airflow workspace"
run: |
git init airflow
git -C airflow remote add origin https://github.com/apache/airflow.git
git -C airflow fetch --depth 1 origin 7fa400745ac7aebc7cc4ec21d3a047e9fb258310
git -C airflow checkout FETCH_HEAD

- name: "Create venv"
run: ./target/debug/uv venv --cache-dir .cache

- name: "Sync airflow workspace"
run: ./target/debug/uv sync --directory airflow --cache-dir .cache

- name: "Prime airflow run"
run: ./target/debug/uv run --directory airflow --cache-dir .cache python -V

- name: "Run benchmarks"
uses: CodSpeedHQ/action@3194d9a39c4d46684cb44bf7207fc56626aad8fd # v4.15.1
with:
Expand Down Expand Up @@ -125,6 +143,19 @@ jobs:
cargo run --bin uv -- pip compile test/requirements/jupyter.in --universal --exclude-newer 2024-08-08 --cache-dir .cache
cargo run --bin uv -- pip compile test/requirements/airflow.in --universal --exclude-newer 2024-08-08 --cache-dir .cache

- name: "Clone airflow workspace"
run: |
git init airflow
git -C airflow remote add origin https://github.com/apache/airflow.git
git -C airflow fetch --depth 1 origin 7fa400745ac7aebc7cc4ec21d3a047e9fb258310
git -C airflow checkout FETCH_HEAD

- name: "Sync airflow workspace"
run: cargo run --bin uv -- sync --directory airflow --cache-dir .cache

- name: "Prime airflow run"
run: cargo run --bin uv -- run --directory airflow --cache-dir .cache python -V

- name: "Build benchmarks"
run: cargo codspeed build --profile profiling -p uv-bench

Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions crates/uv-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ name = "uv"
path = "benches/uv.rs"
harness = false

[[bench]]
name = "airflow_run"
path = "benches/airflow_run.rs"
harness = false

[dev-dependencies]
uv = { path = "../uv", default-features = false }
uv-cache = { workspace = true }
uv-cli = { workspace = true }
uv-client = { workspace = true }
uv-configuration = { workspace = true }
uv-dispatch = { workspace = true }
Expand All @@ -46,14 +53,17 @@ uv-workspace = { workspace = true }
anyhow = { workspace = true }
async_zip = { workspace = true }
astral-tokio-tar = { workspace = true }
clap = { workspace = true }
criterion = { version = "4.0.3", default-features = false, package = "codspeed-criterion-compat", features = ["async_tokio"] }
flate2 = { workspace = true }
fs-err = { workspace = true }
futures = { workspace = true }
jiff = { workspace = true }
reqwest = { workspace = true, features = ["blocking"] }
tempfile = { workspace = true }
tokio = { workspace = true }
tokio-util = { workspace = true }
toml = { workspace = true }

[features]
static = ["uv-extract/static"]
74 changes: 74 additions & 0 deletions crates/uv-bench/benches/airflow_run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//! Benchmark `uv run python -V` in a warm cache against a fully synced airflow workspace.
//!
//! Lives in its own benchmark binary (separate process from `benches/uv.rs`) so that the
//! resolver benchmarks don't pollute the process state before [`uv::run`] is first invoked.

use std::hint::black_box;

use clap::Parser;
use criterion::{Criterion, criterion_group, criterion_main, measurement::WallTime};
use uv_cli::Cli;

#[expect(clippy::print_stderr)]
fn run_noop_airflow(c: &mut Criterion<WallTime>) {
let airflow_dir = std::path::absolute("../../airflow").unwrap();
if !airflow_dir.join("uv.lock").exists() {
let commit = "7fa400745ac7aebc7cc4ec21d3a047e9fb258310";
let repo = "https://github.com/apache/airflow.git";
eprintln!(
"Airflow checkout does not exist, not running benchmark.\n\
To set up:\n\
git init ../airflow\n\
git -C ../airflow remote add origin {repo}\n\
git -C ../airflow fetch --depth 1 origin {commit}\n\
git -C ../airflow checkout FETCH_HEAD"
);
return;
}
let cache_dir = std::path::absolute("../../.cache").unwrap();

let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();

let airflow_dir = airflow_dir.to_string_lossy().to_string();
let cache_dir = cache_dir.to_string_lossy().to_string();

// First call initializes `uv_flags`, logging, miette, etc. Subsequent calls reuse them.
let cli = Cli::try_parse_from([
"uv",
"run",
"--directory",
&airflow_dir,
"--cache-dir",
&cache_dir,
"--quiet",
"python",
"-V",
])
.unwrap();
runtime.block_on(uv::run(cli, true)).unwrap();

c.bench_function("run_noop_airflow", |b| {
b.iter(|| {
let cli = Cli::try_parse_from([
"uv",
"run",
"--directory",
black_box(&airflow_dir),
"--cache-dir",
black_box(&cache_dir),
"--quiet",
"--offline",
"python",
"-V",
])
.unwrap();
runtime.block_on(uv::run(cli, false)).unwrap();
});
});
}

criterion_group!(airflow_run, run_noop_airflow);
criterion_main!(airflow_run);
36 changes: 34 additions & 2 deletions crates/uv-bench/benches/uv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use uv_install_wheel::{InstallState, Layout, LinkMode};
use uv_preview::Preview;
use uv_pypi_types::Scheme;
use uv_python::PythonEnvironment;
use uv_resolver::Manifest;
use uv_resolver::{Lock, Manifest};

const MANY_FILES_WHEEL_FILENAME: &str = "manyfiles-0.0.0-py3-none-any.whl";
const MANY_FILES_WHEEL_FILE_COUNT: usize = 10_000;
Expand Down Expand Up @@ -307,6 +307,37 @@ fn resolve_warm_airflow(c: &mut Criterion<WallTime>) {
// c.bench_function("resolve_warm_airflow_universal", |b| b.iter(&run));
// }

/// Benchmark lock file parsing for the airflow workspace.
fn parse_airflow_lockfile(c: &mut Criterion<WallTime>) {
let lockfile = airflow_lockfile();

c.bench_function("parse_airflow_lockfile", |b| {
b.iter(|| toml::from_str::<Lock>(black_box(&lockfile)).unwrap());
});
}

/// Fetch the airflow lockfile from GitHub, caching it locally.
fn airflow_lockfile() -> String {
let cache_path = std::path::absolute("../../.cache/airflow.uv.lock").unwrap();
if let Ok(contents) = fs_err::read_to_string(&cache_path) {
return contents;
}

let url = "https://raw.githubusercontent.com/apache/airflow/7fa400745ac7aebc7cc4ec21d3a047e9fb258310/uv.lock";
let error_message = "Failed to fetch airflow lockfile from GitHub";
let response = reqwest::blocking::get(url)
.expect(error_message)
.error_for_status()
.expect(error_message)
.text()
.expect(error_message);

fs_err::create_dir_all(cache_path.parent().unwrap()).unwrap();
fs_err::write(&cache_path, &response).unwrap();

response
}

criterion_group!(
uv,
unpack_sdist_many_files,
Expand All @@ -315,7 +346,8 @@ criterion_group!(
install_wheel_many_files,
resolve_warm_jupyter,
resolve_warm_jupyter_universal,
resolve_warm_airflow
resolve_warm_airflow,
parse_airflow_lockfile,
);
criterion_main!(uv);

Expand Down
1 change: 1 addition & 0 deletions crates/uv-build-frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ workspace = true

[dependencies]
uv-auth = { workspace = true }
uv-cache = { workspace = true }
uv-cache-key = { workspace = true }
uv-configuration = { workspace = true }
uv-distribution = { workspace = true }
Expand Down
5 changes: 5 additions & 0 deletions crates/uv-build-frontend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use tokio::process::Command;
use tokio::sync::{Mutex, Semaphore};
use tracing::{Instrument, debug, info_span, instrument, warn};
use uv_auth::CredentialsCache;
use uv_cache::Cache;
use uv_cache_key::cache_digest;
use uv_configuration::{BuildKind, BuildOutput, NoSources};
use uv_distribution::BuildRequires;
Expand Down Expand Up @@ -321,6 +322,7 @@ impl SourceBuild {
fallback_package_name,
locations,
&no_sources,
build_context.cache(),
workspace_cache,
credentials_cache,
)
Expand Down Expand Up @@ -572,6 +574,7 @@ impl SourceBuild {
package_name: Option<&PackageName>,
locations: &IndexLocations,
no_sources: &NoSources,
cache: &Cache,
workspace_cache: &WorkspaceCache,
credentials_cache: &CredentialsCache,
) -> Result<(Pep517Backend, Option<Project>), Box<Error>> {
Expand Down Expand Up @@ -652,6 +655,7 @@ impl SourceBuild {
locations,
no_sources,
true,
cache,
workspace_cache,
credentials_cache,
)
Expand Down Expand Up @@ -1100,6 +1104,7 @@ async fn create_pep517_build_environment(
build_context
.source_tree_editable_policy()
.workspace_member_editable(None),
build_context.cache(),
workspace_cache,
credentials_cache,
)
Expand Down
13 changes: 10 additions & 3 deletions crates/uv-distribution/src/metadata/build_requires.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::BTreeMap;
use std::path::Path;

use uv_auth::CredentialsCache;
use uv_cache::Cache;
use uv_configuration::NoSources;
use uv_distribution_types::{
ExtraBuildRequirement, ExtraBuildRequires, IndexLocations, Requirement,
Expand Down Expand Up @@ -43,7 +44,8 @@ impl BuildRequires {
locations: &IndexLocations,
sources: &NoSources,
editable: bool,
cache: &WorkspaceCache,
cache: &Cache,
workspace_cache: &WorkspaceCache,
credentials_cache: &CredentialsCache,
) -> Result<Self, MetadataError> {
let discovery = if sources.all() {
Expand All @@ -54,8 +56,13 @@ impl BuildRequires {
} else {
DiscoveryOptions::default()
};
let Some(project_workspace) =
ProjectWorkspace::from_maybe_project_root(install_path, &discovery, cache).await?
let Some(project_workspace) = ProjectWorkspace::from_maybe_project_root(
install_path,
&discovery,
cache,
workspace_cache,
)
.await?
else {
return Ok(Self::from_metadata23(metadata));
};
Expand Down
13 changes: 8 additions & 5 deletions crates/uv-distribution/src/metadata/dependency_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ use std::collections::BTreeMap;
use std::path::{Path, PathBuf};

use uv_auth::CredentialsCache;
use uv_cache::Cache;
use uv_configuration::NoSources;
use uv_distribution_types::{IndexLocations, Requirement};
use uv_normalize::{GroupName, PackageName};
use uv_workspace::dependency_groups::FlatDependencyGroups;
use uv_workspace::pyproject::{Sources, ToolUvSources};
use uv_workspace::{
DiscoveryOptions, MemberDiscovery, VirtualProject, WorkspaceCache, WorkspaceError,
WorkspaceErrorKind,
};

use crate::metadata::{GitWorkspaceMember, LoweredRequirement, MetadataError};
Expand Down Expand Up @@ -57,7 +59,8 @@ impl SourcedDependencyGroups {
git_member: Option<&GitWorkspaceMember<'_>>,
locations: &IndexLocations,
no_sources: NoSources,
cache: &WorkspaceCache,
cache: &Cache,
workspace_cache: &WorkspaceCache,
credentials_cache: &CredentialsCache,
) -> Result<Self, MetadataError> {
// If the `pyproject.toml` doesn't exist, fail early.
Expand All @@ -80,15 +83,15 @@ impl SourcedDependencyGroups {
} else {
MemberDiscovery::None
},
..DiscoveryOptions::default()
};

// The subsequent API takes an absolute path to the dir the pyproject is in
let empty = PathBuf::new();
let absolute_pyproject_path =
std::path::absolute(pyproject_path).map_err(WorkspaceError::Normalize)?;
let absolute_pyproject_path = std::path::absolute(pyproject_path)
.map_err(|err| WorkspaceError::from(WorkspaceErrorKind::Normalize(err)))?;
let project_dir = absolute_pyproject_path.parent().unwrap_or(&empty);
let project = VirtualProject::discover(project_dir, &discovery, cache).await?;
let project =
VirtualProject::discover(project_dir, &discovery, cache, workspace_cache).await?;

// Collect the dependency groups.
let dependency_groups =
Expand Down
Loading