perf: don't double-box task outputs
This commit is contained in:
1 parent
b48b3a5a2e
commit
49be497964
1 file changed
+6
-7
+6
-7
@@ -10,12 +10,12 @@ use std::collections::{HashMap, HashSet, VecDeque};
|
|||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::hash::{BuildHasher, Hasher};
|
use std::hash::{BuildHasher, Hasher};
|
||||||
use std::panic::AssertUnwindSafe;
|
use std::panic::AssertUnwindSafe;
|
||||||
use std::pin::Pin;
|
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use futures_util::future::BoxFuture;
|
||||||
use futures_util::{stream::FuturesUnordered, FutureExt, StreamExt, TryFutureExt};
|
use futures_util::{stream::FuturesUnordered, FutureExt, StreamExt, TryFutureExt};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
@@ -28,8 +28,6 @@ use crate::node::{ExecutableNode, TypedNode};
|
|||||||
use crate::task::Task;
|
use crate::task::Task;
|
||||||
use crate::types::{NodeId, Pending, TaskHandle};
|
use crate::types::{NodeId, Pending, TaskHandle};
|
||||||
|
|
||||||
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
|
|
||||||
|
|
||||||
// Guard to ensure run_lock is released even on early return or panic
|
// Guard to ensure run_lock is released even on early return or panic
|
||||||
struct RunGuard<'a> {
|
struct RunGuard<'a> {
|
||||||
lock: &'a AtomicBool,
|
lock: &'a AtomicBool,
|
||||||
@@ -319,8 +317,8 @@ impl DagRunner {
|
|||||||
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self, spawner)))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self, spawner)))]
|
||||||
pub async fn run<S, F>(&self, spawner: S) -> DagResult<()>
|
pub async fn run<S, F>(&self, spawner: S) -> DagResult<()>
|
||||||
where
|
where
|
||||||
S: Fn(BoxFuture<'static, DagResult<(NodeId, Arc<dyn Any + Send + Sync>)>>) -> F,
|
S: Fn(BoxFuture<'static, DagResult<Arc<dyn Any + Send + Sync>>>) -> F,
|
||||||
F: Future<Output = DagResult<(NodeId, Arc<dyn Any + Send + Sync>)>>,
|
F: Future<Output = DagResult<Arc<dyn Any + Send + Sync>>>,
|
||||||
{
|
{
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
info!("starting DAG execution");
|
info!("starting DAG execution");
|
||||||
@@ -474,14 +472,15 @@ impl DagRunner {
|
|||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let inner_future = spawner(node.execute_with_deps(dependencies));
|
||||||
// Spawn the task using the provided spawner
|
// Spawn the task using the provided spawner
|
||||||
let inner_future = async move {
|
let inner_future = async move {
|
||||||
let result = node.execute_with_deps(dependencies).await?;
|
let result = inner_future.await?;
|
||||||
Ok((node_id, result))
|
Ok((node_id, result))
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
AssertUnwindSafe(spawner(Box::pin(inner_future)))
|
AssertUnwindSafe(inner_future)
|
||||||
.catch_unwind()
|
.catch_unwind()
|
||||||
.unwrap_or_else(move |panic_payload| {
|
.unwrap_or_else(move |panic_payload| {
|
||||||
// Convert panic to error
|
// Convert panic to error
|
||||||
|
|||||||
Reference in new issue
Block a user