feat: dagrunner, initial version

This commit is contained in:
swaits committed 2025-10-07 16:31:03 -07:00
commit 7412287ee4
122 files changed
+23101

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
//! 10,000 task breakdown benchmarks - construction vs execution
use criterion::Criterion;
use dagx::{task_fn, DagRunner};
pub fn bench_10k_breakdown(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();
let mut group = c.benchmark_group("10k_tasks");
group.measurement_time(std::time::Duration::from_secs(10));
// a) Adding 10k tasks (construction only)
group.bench_function("construction", |b| {
b.iter(|| {
let dag = DagRunner::new();
for i in 0..10_000 {
dag.add_task(task_fn(move |_: ()| async move { i }));
}
});
});
// b) Full lifecycle: add 10k tasks + run them
group.bench_function("full_execution", |b| {
b.iter(|| {
rt.block_on(async {
let dag = DagRunner::new();
for i in 0..10_000 {
dag.add_task(task_fn(move |_: ()| async move { i }));
}
dag.run(|fut| {
tokio::spawn(fut);
})
.await
.unwrap();
})
});
});
// c) Execution only (pre-built DAG, just run)
group.bench_function("execution_only", |b| {
// Pre-build the DAG outside the measurement
let dag = DagRunner::new();
for i in 0..10_000 {
dag.add_task(task_fn(move |_: ()| async move { i }));
}
b.iter(|| {
rt.block_on(async {
dag.run(|fut| {
tokio::spawn(fut);
})
.await
.unwrap();
})
});
});
group.finish();
}
+36
View File
@@ -0,0 +1,36 @@
//! Diamond pattern benchmarks (fan-out then fan-in)
use criterion::Criterion;
use dagx::{task_fn, DagRunner};
pub fn bench_diamond(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();
c.bench_function("diamond_pattern_50", |b| {
b.iter(|| {
rt.block_on(async {
let dag = DagRunner::new();
for i in 0..50 {
let source = dag.add_task(task_fn(move |_: ()| async move { i }));
let left = dag
.add_task(task_fn(|x: i32| async move { x * 2 }))
.depends_on(&source);
let right = dag
.add_task(task_fn(|x: i32| async move { x * 3 }))
.depends_on(&source);
dag.add_task(task_fn(|(l, r): (i32, i32)| async move { l + r }))
.depends_on((&left, &right));
}
dag.run(|fut| {
tokio::spawn(fut);
})
.await
.unwrap();
})
});
});
}
+83
View File
@@ -0,0 +1,83 @@
//! Fan-out pattern benchmarks (1 → N dependencies)
use criterion::Criterion;
use dagx::{task_fn, DagRunner};
pub fn bench_fanout(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();
// Fan-out pattern (1 → n) with simple i32
c.bench_function("fanout_1_to_100_i32", |b| {
b.iter(|| {
rt.block_on(async {
let dag = DagRunner::new();
let source = dag.add_task(task_fn(|_: ()| async { 42 }));
for i in 0..100 {
dag.add_task(task_fn(move |x: i32| async move { x + i }))
.depends_on(&source);
}
dag.run(|fut| {
tokio::spawn(fut);
})
.await
.unwrap();
})
});
});
// Fan-out pattern with Vec (automatic Arc wrapping)
c.bench_function("fanout_1_to_100_vec", |b| {
b.iter(|| {
rt.block_on(async {
let dag = DagRunner::new();
let source = dag.add_task(task_fn(|_: ()| async {
// Create 1000 strings - framework wraps in Arc automatically
(0..1000).map(|i| format!("Item {}", i)).collect::<Vec<_>>()
}));
for i in 0..100 {
dag.add_task(task_fn(move |data: Vec<String>| async move {
// Each consumer gets data extracted from Arc
data.iter().filter(|s| s.contains(&i.to_string())).count()
}))
.depends_on(&source);
}
dag.run(|fut| {
tokio::spawn(fut);
})
.await
.unwrap();
})
});
});
// Arc overhead benchmark - shows cost on Copy types
// For Copy types like usize, Arc adds overhead (atomic refcounting + indirection)
// For heap types like Vec, Arc overhead is negligible compared to clone cost
c.bench_function("arc_overhead_copy_type", |b| {
b.iter(|| {
rt.block_on(async {
let dag = DagRunner::new();
// Source produces a simple Copy type (usize)
// Framework wraps in Arc<usize> internally
let source = dag.add_task(task_fn(|_: ()| async { 42usize }));
// 100 dependents - Arc overhead visible on Copy types
for i in 0..100 {
dag.add_task(task_fn(move |x: usize| async move { x + i }))
.depends_on(&source);
}
dag.run(|fut| {
tokio::spawn(fut);
})
.await
.unwrap();
})
});
});
}
+5
View File
@@ -0,0 +1,5 @@
//! DAG pattern benchmarks
pub mod breakdown;
pub mod diamond;
pub mod fanout;