Skip to content

Commit

Permalink
feat: add sorting bench and makes test same as feature test (#897)
Browse files Browse the repository at this point in the history
Takes the updated test from #892 and adds sorting bench.
  • Loading branch information
tdejager authored Oct 7, 2024
1 parent d1155f6 commit bc48aaa
Show file tree
Hide file tree
Showing 11 changed files with 608 additions and 16 deletions.
14 changes: 10 additions & 4 deletions crates/rattler_solve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ license.workspace = true
readme.workspace = true

[dependencies]
rattler_conda_types = { path="../rattler_conda_types", version = "0.28.1", default-features = false }
rattler_digest = { path="../rattler_digest", version = "1.0.2", default-features = false }
rattler_conda_types = { path = "../rattler_conda_types", version = "0.28.1", default-features = false }
rattler_digest = { path = "../rattler_digest", version = "1.0.2", default-features = false }
libc = { workspace = true, optional = true }
chrono = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
itertools = { workspace = true }
url = { workspace = true }
tempfile = { workspace = true }
rattler_libsolv_c = { path="../rattler_libsolv_c", version = "1.0.2", default-features = false, optional = true }
rattler_libsolv_c = { path = "../rattler_libsolv_c", version = "1.0.2", default-features = false, optional = true }
resolvo = { workspace = true, optional = true }
futures = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
Expand All @@ -29,7 +29,9 @@ serde = { workspace = true, optional = true }
criterion = { workspace = true }
insta = { workspace = true, features = ["yaml"] }
once_cell = { workspace = true }
rattler_repodata_gateway = { path = "../rattler_repodata_gateway", default-features = false, features = ["sparse"] }
rattler_repodata_gateway = { path = "../rattler_repodata_gateway", default-features = false, features = [
"sparse",
] }
rstest = { workspace = true }
serde_json = { workspace = true }
similar-asserts = { workspace = true }
Expand All @@ -46,5 +48,9 @@ resolvo = ["dep:resolvo", "dep:futures"]
name = "bench"
harness = false

[[bench]]
name = "sorting_bench"
harness = false

[package.metadata.docs.rs]
all-features = true
79 changes: 79 additions & 0 deletions crates/rattler_solve/benches/sorting_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use std::path::Path;

use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
use futures::FutureExt;
use rattler_conda_types::{Channel, MatchSpec};
use rattler_repodata_gateway::sparse::SparseRepoData;
use rattler_solve::resolvo::CondaDependencyProvider;
use rattler_solve::ChannelPriority;
use resolvo::SolverCache;

fn bench_sort(c: &mut Criterion, sparse_repo_data: &SparseRepoData, spec: &str) {
let match_spec =
MatchSpec::from_str(spec, rattler_conda_types::ParseStrictness::Lenient).unwrap();
let package_name = match_spec.name.clone().unwrap();

let repodata =
SparseRepoData::load_records_recursive([sparse_repo_data], [package_name.clone()], None)
.expect("failed to load records");

// Construct a cache
c.bench_function(&format!("sort {}", spec), |b| {
// Get the candidates for the package
b.iter_batched(
|| (package_name.clone(), match_spec.clone()),
|(package_name, match_spec)| {
// Construct dependency provider
let dependency_provider = CondaDependencyProvider::new(
repodata.iter().map(|r| r.iter().collect()),
&[],
&[],
&[],
&[match_spec.clone()],
None,
ChannelPriority::default(),
None,
rattler_solve::SolveStrategy::Highest,
)
.expect("failed to create dependency provider");

let name = dependency_provider
.pool
.intern_package_name(package_name.as_normalized());
let version_set = dependency_provider
.pool
.intern_version_set(name, match_spec.into_nameless().1.into());

let cache = SolverCache::new(dependency_provider);

let deps = cache
.get_or_cache_sorted_candidates(version_set.into())
.now_or_never()
.expect("failed to get candidates")
.expect("solver requested cancellation");
black_box(deps);
},
BatchSize::SmallInput,
);
});
}

fn criterion_benchmark(c: &mut Criterion) {
let channel_path = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../..")
.join("test-data")
.join("channels")
.join("conda-forge");
let repodata_json_path = channel_path.join("linux-64").join("repodata.json");
let channel = Channel::from_directory(&channel_path);

let sparse_repo_data = SparseRepoData::new(channel, "linux-64", repodata_json_path, None)
.expect("failed to load sparse repodata");

bench_sort(c, &sparse_repo_data, "pytorch");
bench_sort(c, &sparse_repo_data, "python");
bench_sort(c, &sparse_repo_data, "tensorflow");
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
source: crates/rattler_solve/tests/sorting.rs
expression: "create_sorting_snapshot(spec, solve_strategy)"
---
abess=0.4.5=py310hc4a4660_1
abess=0.4.5=py39hac2352c_1
abess=0.4.5=py38h514daf8_1
abess=0.4.5=py37h48bf904_1
abess=0.4.5=py39hac2352c_0
abess=0.4.5=py38h514daf8_0
abess=0.4.5=py37h48bf904_0
abess=0.4.4=py39hac2352c_1
abess=0.4.4=py38h514daf8_1
abess=0.4.4=py37h48bf904_1
abess=0.4.4=py39hac2352c_0
abess=0.4.4=py38h514daf8_0
abess=0.4.4=py37h48bf904_0
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
---
source: crates/rattler_solve/tests/sorting.rs
expression: "create_sorting_snapshot(spec, solve_strategy)"
---
certifi=2022.6.15=py310hff52083_0
certifi=2022.6.15=py39hf3d152e_0
certifi=2022.6.15=py38h578d9bd_0
certifi=2022.6.15=py37h89c1867_0
certifi=2022.6.15=py39h4162558_0
certifi=2022.6.15=py38h373033e_0
certifi=2022.5.18.1=py310hff52083_0
certifi=2022.5.18.1=py39hf3d152e_0
certifi=2022.5.18.1=py38h578d9bd_0
certifi=2022.5.18.1=py37h89c1867_0
certifi=2022.5.18.1=py39h4162558_0
certifi=2022.5.18.1=py38h373033e_0
certifi=2022.5.18=py310hff52083_0
certifi=2022.5.18=py39hf3d152e_0
certifi=2022.5.18=py38h578d9bd_0
certifi=2022.5.18=py37h89c1867_0
certifi=2022.5.18=py39h4162558_0
certifi=2022.5.18=py38h373033e_0
certifi=2021.10.8=py310hff52083_2
certifi=2021.10.8=py39hf3d152e_2
certifi=2021.10.8=py38h578d9bd_2
certifi=2021.10.8=py37h89c1867_2
certifi=2021.10.8=py39h4162558_2
certifi=2021.10.8=py38h373033e_2
certifi=2021.10.8=py310hff52083_1
certifi=2021.10.8=py39hf3d152e_1
certifi=2021.10.8=py38h578d9bd_1
certifi=2021.10.8=py37h89c1867_1
certifi=2021.10.8=py37h9c2f6ca_1
certifi=2021.10.8=py39hf3d152e_0
certifi=2021.10.8=py38h578d9bd_0
certifi=2021.10.8=py37h89c1867_0
certifi=2021.10.8=py37h9c2f6ca_0
certifi=2021.5.30=py39hf3d152e_0
certifi=2021.5.30=py38h578d9bd_0
certifi=2021.5.30=py37h89c1867_0
certifi=2021.5.30=py36h5fab9bb_0
certifi=2021.5.30=py37h9c2f6ca_0
certifi=2021.5.30=py36hd000896_0
certifi=2020.12.5=py39hf3d152e_1
certifi=2020.12.5=py38h578d9bd_1
certifi=2020.12.5=py37h89c1867_1
certifi=2020.12.5=py36h5fab9bb_1
certifi=2020.12.5=py37h9c2f6ca_1
certifi=2020.12.5=py36hd000896_1
certifi=2020.12.5=py39hf3d152e_0
certifi=2020.12.5=py38h578d9bd_0
certifi=2020.12.5=py37h89c1867_0
certifi=2020.12.5=py36h5fab9bb_0
certifi=2020.12.5=py36hd000896_0
certifi=2020.11.8=py39hf3d152e_0
certifi=2020.11.8=py38h578d9bd_0
certifi=2020.11.8=py37h89c1867_0
certifi=2020.11.8=py36h5fab9bb_0
certifi=2020.11.8=py36hd000896_0
certifi=2020.6.20=py39h079e4ff_2
certifi=2020.6.20=py38h924ce5b_2
certifi=2020.6.20=py37he5f6b98_2
certifi=2020.6.20=py36h9880bd3_2
certifi=2020.6.20=py36ha6c21b1_2
certifi=2020.6.20=py38h924ce5b_1
certifi=2020.6.20=py37he5f6b98_1
certifi=2020.6.20=py36h9880bd3_1
certifi=2020.6.20=py36ha6c21b1_1
certifi=2020.6.20=py38h32f6830_0
certifi=2020.6.20=py37hc8dfbb8_0
certifi=2020.6.20=py36h9f0ad1d_0
certifi=2020.6.20=py36hc560c46_0
certifi=2020.4.5.2=py38h32f6830_0
certifi=2020.4.5.2=py37hc8dfbb8_0
certifi=2020.4.5.2=py36h9f0ad1d_0
certifi=2020.4.5.2=py36hc560c46_0
certifi=2020.4.5.1=py38h32f6830_0
certifi=2020.4.5.1=py37hc8dfbb8_0
certifi=2020.4.5.1=py36h9f0ad1d_0
certifi=2020.4.5.1=py36hc560c46_0
certifi=2019.11.28=py38h32f6830_1
certifi=2019.11.28=py37hc8dfbb8_1
certifi=2019.11.28=py36h9f0ad1d_1
certifi=2019.11.28=py27h8c360ce_1
certifi=2019.11.28=py36hc560c46_1
certifi=2019.11.28=py38h32f6830_0
certifi=2019.11.28=py38_0
certifi=2019.11.28=py37hc8dfbb8_0
certifi=2019.11.28=py37_0
certifi=2019.11.28=py36h9f0ad1d_0
certifi=2019.11.28=py36hc560c46_0
certifi=2019.11.28=py36_0
certifi=2019.11.28=py27h8c360ce_0
certifi=2019.11.28=py27_0
certifi=2019.9.11=py38_0
certifi=2019.9.11=py37_0
certifi=2019.9.11=py36_0
certifi=2019.9.11=py27_0
certifi=2019.6.16=py37_1
certifi=2019.6.16=py36_1
certifi=2019.6.16=py27_1
certifi=2019.6.16=py37_0
certifi=2019.6.16=py36_0
certifi=2019.6.16=py27_0
certifi=2019.3.9=py37_0
certifi=2019.3.9=py36_0
certifi=2019.3.9=py27_0
certifi=2018.11.29=py37_1000
certifi=2018.11.29=py36_1000
certifi=2018.11.29=py27_1000
certifi=2018.10.15=py37_1000
certifi=2018.10.15=py36_1000
certifi=2018.10.15=py27_1000
certifi=2018.8.24=py37_1001
certifi=2018.8.24=py36_1001
certifi=2018.8.24=py35_1001
certifi=2018.8.24=py27_1001
certifi=2018.8.24=py36_1
certifi=2018.8.24=py35_1
certifi=2018.8.24=py27_1
certifi=2018.8.24=py36_0
certifi=2018.8.24=py35_0
certifi=2018.8.24=py27_0
certifi=2018.8.13=py36_0
certifi=2018.8.13=py35_0
certifi=2018.8.13=py27_0
certifi=2018.4.16=py37_0
certifi=2018.4.16=py36_0
certifi=2018.4.16=py35_0
certifi=2018.4.16=py27_0
certifi=2018.1.18=py36_0
certifi=2018.1.18=py35_0
certifi=2018.1.18=py27_0
certifi=2017.11.5=py36_0
certifi=2017.11.5=py35_0
certifi=2017.11.5=py27_0
certifi=2017.7.27.1=py36_0
certifi=2017.7.27.1=py35_0
certifi=2017.7.27.1=py27_0
certifi=2017.4.17=py36_0
certifi=2017.4.17=py35_0
certifi=2017.4.17=py27_0
certifi=2017.1.23=py36_0
certifi=2017.1.23=py35_0
certifi=2017.1.23=py34_0
certifi=2017.1.23=py27_0
certifi=2016.9.26=py36_0
certifi=2016.9.26=py35_0
certifi=2016.9.26=py34_0
certifi=2016.9.26=py27_0
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
source: crates/rattler_solve/tests/sorting.rs
expression: "create_sorting_snapshot(spec, solve_strategy)"
---
libgcc-ng=12.1.0=h8d9b700_16
libgcc-ng=11.3.0=h36d3e0d_16
libgcc-ng=11.2.0=h1d223b6_16
libgcc-ng=11.2.0=h1d223b6_15
libgcc-ng=11.2.0=h1d223b6_14
libgcc-ng=11.2.0=h1d223b6_13
libgcc-ng=11.2.0=h1d223b6_12
libgcc-ng=11.2.0=h1d223b6_11
libgcc-ng=11.2.0=h1d223b6_10
libgcc-ng=11.2.0=h1d223b6_9
libgcc-ng=11.2.0=h1d223b6_8
libgcc-ng=11.1.0=hc902ee8_8
libgcc-ng=11.1.0=hc902ee8_7
libgcc-ng=11.1.0=hc902ee8_6
libgcc-ng=11.1.0=hc902ee8_5
libgcc-ng=11.1.0=hc902ee8_4
libgcc-ng=11.1.0=hc902ee8_3
libgcc-ng=10.4.0=hffabe06_16
libgcc-ng=10.3.0=hb27ad48_16
libgcc-ng=10.3.0=hb27ad48_15
libgcc-ng=10.3.0=hb27ad48_14
libgcc-ng=10.3.0=hb27ad48_13
libgcc-ng=10.3.0=hb27ad48_12
libgcc-ng=10.3.0=hb27ad48_11
libgcc-ng=10.3.0=hb27ad48_10
libgcc-ng=10.3.0=hb27ad48_9
libgcc-ng=10.3.0=hb27ad48_8
libgcc-ng=10.3.0=hb27ad48_7
libgcc-ng=10.3.0=hb27ad48_6
libgcc-ng=10.3.0=hb27ad48_5
libgcc-ng=10.3.0=hb27ad48_4
libgcc-ng=10.3.0=hb27ad48_3
libgcc-ng=9.5.0=hea2341a_16
libgcc-ng=9.4.0=hfa6338b_16
libgcc-ng=9.4.0=hfa6338b_15
libgcc-ng=9.4.0=hfa6338b_14
libgcc-ng=9.4.0=hfa6338b_13
libgcc-ng=9.4.0=hfa6338b_12
libgcc-ng=9.4.0=hfa6338b_11
libgcc-ng=9.4.0=hfa6338b_10
libgcc-ng=9.4.0=hfa6338b_9
libgcc-ng=9.4.0=hfa6338b_8
libgcc-ng=9.4.0=hfa6338b_7
libgcc-ng=9.4.0=hfa6338b_6
libgcc-ng=9.4.0=hfa6338b_5
libgcc-ng=9.4.0=hfa6338b_4
libgcc-ng=9.4.0=hfa6338b_3
libgcc-ng=9.3.0=h2828fa1_19
libgcc-ng=9.3.0=h2828fa1_18
libgcc-ng=9.3.0=h5dbcf3e_17
libgcc-ng=9.3.0=h24d8f2e_16
libgcc-ng=9.3.0=h24d8f2e_15
libgcc-ng=9.3.0=h24d8f2e_14
libgcc-ng=9.3.0=h24d8f2e_13
libgcc-ng=9.3.0=h24d8f2e_12
libgcc-ng=9.3.0=h24d8f2e_11
libgcc-ng=9.2.0=h24d8f2e_2
libgcc-ng=9.2.0=hdf63c60_0
libgcc-ng=8.5.0=h9c19199_16
libgcc-ng=8.5.0=h9c19199_15
libgcc-ng=8.5.0=h9c19199_14
libgcc-ng=8.5.0=h9c19199_13
libgcc-ng=8.5.0=h9c19199_12
libgcc-ng=8.5.0=h9c19199_11
libgcc-ng=8.5.0=h9c19199_10
libgcc-ng=8.5.0=h9c19199_9
libgcc-ng=8.5.0=h9c19199_8
libgcc-ng=8.4.0=h2828fa1_19
libgcc-ng=8.4.0=h2828fa1_18
libgcc-ng=8.4.0=h5dbcf3e_17
libgcc-ng=8.4.0=h24d8f2e_16
libgcc-ng=8.4.0=h24d8f2e_15
libgcc-ng=8.4.0=h24d8f2e_14
libgcc-ng=7.5.0=h2828fa1_20
libgcc-ng=7.5.0=h2828fa1_19
libgcc-ng=7.5.0=h2828fa1_18
libgcc-ng=7.5.0=h5dbcf3e_17
libgcc-ng=7.5.0=h24d8f2e_16
libgcc-ng=7.5.0=h24d8f2e_15
libgcc-ng=7.5.0=h24d8f2e_14
libgcc-ng=7.5.0=h24d8f2e_13
libgcc-ng=7.5.0=h24d8f2e_12
libgcc-ng=7.5.0=h24d8f2e_11
libgcc-ng=7.5.0=h24d8f2e_10
libgcc-ng=7.5.0=h24d8f2e_9
libgcc-ng=7.3.0=h24d8f2e_5
libgcc-ng=7.3.0=h24d8f2e_4
libgcc-ng=7.3.0=hdf63c60_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: crates/rattler_solve/tests/sorting.rs
expression: "create_sorting_snapshot(spec, solve_strategy)"
---
libuuid=2.32.1=h7f98852_1000
libuuid=2.32.1=h14c3975_1000
Loading

0 comments on commit bc48aaa

Please sign in to comment.