-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved Concurrent metadata fetching (#29)
* chore: update rust-toolchain to latest stable release * feat: concurrent metadata fetching * more concurrency * feat: sort_candidates is now async * fix: fmt and clippy * refactor: no more channels * refactor: everything concurrent * fix: tests and clippy * feat: runtime agnostic impl * fix: forgot public docs * fix: remove outdated comment --------- Co-authored-by: Adolfo Ochagavía <[email protected]> Co-authored-by: Tim de Jager <[email protected]>
- Loading branch information
1 parent
357a64d
commit 4c04afc
Showing
10 changed files
with
785 additions
and
400 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "resolvo" | ||
version = "0.3.0" | ||
authors = ["Adolfo Ochagavía <[email protected]>", "Bas Zalmstra <[email protected]>", "Tim de Jager <[email protected]>" ] | ||
authors = ["Adolfo Ochagavía <[email protected]>", "Bas Zalmstra <[email protected]>", "Tim de Jager <[email protected]>"] | ||
description = "Fast package resolver written in Rust (CDCL based SAT solving)" | ||
keywords = ["dependency", "solver", "version"] | ||
categories = ["algorithms"] | ||
|
@@ -10,17 +10,25 @@ repository = "https://github.com/mamba-org/resolvo" | |
license = "BSD-3-Clause" | ||
edition = "2021" | ||
readme = "README.md" | ||
resolver = "2" | ||
|
||
[dependencies] | ||
itertools = "0.11.0" | ||
itertools = "0.12.1" | ||
petgraph = "0.6.4" | ||
tracing = "0.1.37" | ||
elsa = "1.9.0" | ||
bitvec = "1.0.1" | ||
serde = { version = "1.0", features = ["derive"], optional = true } | ||
futures = { version = "0.3.30", default-features = false, features = ["alloc"] } | ||
event-listener = "5.0.0" | ||
|
||
tokio = { version = "1.35.1", features = ["rt"], optional = true } | ||
async-std = { version = "1.12.0", default-features = false, features = ["alloc", "default"], optional = true } | ||
|
||
[dev-dependencies] | ||
insta = "1.31.0" | ||
indexmap = "2.0.0" | ||
proptest = "1.2.0" | ||
tracing-test = { version = "0.2.4", features = ["no-env-filter"] } | ||
tokio = { version = "1.35.1", features = ["time", "rt"] } | ||
resolvo = { path = ".", features = ["tokio"] } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.72.0 | ||
1.75.0 |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//! Solving in resolvo is a compute heavy operation. However, while computing the solver will | ||
//! request additional information from the [`crate::DependencyProvider`] and a dependency provider | ||
//! might want to perform multiple requests concurrently. To that end the | ||
//! [`crate::DependencyProvider`]s methods are async. The implementer can implement the async | ||
//! operations in any way they choose including with any runtime they choose. | ||
//! However, the solver itself is completely single threaded, but it still has to await the calls to | ||
//! the dependency provider. Using the [`AsyncRuntime`] allows the caller of the solver to choose | ||
//! how to await the futures. | ||
//! | ||
//! By default, the solver uses the [`NowOrNeverRuntime`] runtime which polls any future once. If | ||
//! the future yields (thus requiring an additional poll) the runtime panics. If the methods of | ||
//! [`crate::DependencyProvider`] do not yield (e.g. do not `.await`) this will suffice. | ||
//! | ||
//! Only if the [`crate::DependencyProvider`] implementation yields you will need to provide a | ||
//! [`AsyncRuntime`] to the solver. | ||
//! | ||
//! ## `tokio` | ||
//! | ||
//! The [`AsyncRuntime`] trait is implemented both for [`tokio::runtime::Handle`] and for | ||
//! [`tokio::runtime::Runtime`]. | ||
//! | ||
//! ## `async-std` | ||
//! | ||
//! Use the [`AsyncStdRuntime`] struct to block on async methods from the | ||
//! [`crate::DependencyProvider`] using the `async-std` executor. | ||
|
||
use futures::FutureExt; | ||
use std::future::Future; | ||
|
||
/// A trait to wrap an async runtime. | ||
pub trait AsyncRuntime { | ||
/// Runs the given future on the current thread, blocking until it is complete, and yielding its | ||
/// resolved result. | ||
fn block_on<F: Future>(&self, f: F) -> F::Output; | ||
} | ||
|
||
/// The simplest runtime possible evaluates and consumes the future, returning the resulting | ||
/// output if the future is ready after the first call to [`Future::poll`]. If the future does | ||
/// yield the runtime panics. | ||
/// | ||
/// This assumes that the passed in future never yields. For purely blocking computations this | ||
/// is the preferred method since it also incurs very little overhead and doesn't require the | ||
/// inclusion of a heavy-weight runtime. | ||
#[derive(Default, Copy, Clone)] | ||
pub struct NowOrNeverRuntime; | ||
|
||
impl AsyncRuntime for NowOrNeverRuntime { | ||
fn block_on<F: Future>(&self, f: F) -> F::Output { | ||
f.now_or_never() | ||
.expect("can only use non-yielding futures with the NowOrNeverRuntime") | ||
} | ||
} | ||
|
||
#[cfg(feature = "tokio")] | ||
impl AsyncRuntime for tokio::runtime::Handle { | ||
fn block_on<F: Future>(&self, f: F) -> F::Output { | ||
self.block_on(f) | ||
} | ||
} | ||
|
||
#[cfg(feature = "tokio")] | ||
impl AsyncRuntime for tokio::runtime::Runtime { | ||
fn block_on<F: Future>(&self, f: F) -> F::Output { | ||
self.block_on(f) | ||
} | ||
} | ||
|
||
/// An implementation of [`AsyncRuntime`] that spawns and awaits any passed future on the current | ||
/// thread. | ||
#[cfg(feature = "async-std")] | ||
pub struct AsyncStdRuntime; | ||
|
||
#[cfg(feature = "async-std")] | ||
impl AsyncRuntime for AsyncStdRuntime { | ||
fn block_on<F: Future>(&self, f: F) -> F::Output { | ||
async_std::task::block_on(f) | ||
} | ||
} |
Oops, something went wrong.