Skip to content
Merged
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
87 changes: 72 additions & 15 deletions Cargo.lock

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

18 changes: 12 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repository = "https://github.com/NthTensor/Forte"

[workspace]
resolver = "2"
members = ["ci", "rayon-compat"]
members = ["ci"]

[dependencies]
arraydeque = "0.5.1"
Expand All @@ -26,6 +26,8 @@ divan = "0.1.17"
rayon = "1.10.0"
chili = "0.2"
bevy_tasks = { version = "0.16.1", features = [ "multi_threaded" ] }
# Used for some benchmarks
dashmap = "6.1.0"
# Used for A/B perf testing
criterion = { version = "0.5" }

Expand All @@ -36,7 +38,7 @@ shuttle = ["dep:shuttle"]
debug = true

[profile.bench]
debug = true
opt-level = 3

# Custom profile for shuttle tests: enable release optimizations so that the shuttle
# tests are less slow, but don't disable debug assertions.
Expand Down Expand Up @@ -68,14 +70,18 @@ missing_docs = "warn"
unsafe_op_in_unsafe_fn = "warn"
unused_qualifications = "warn"

[[test]]
name = "integration"
path = "tests/tests.rs"

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

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

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

[[bench]]
name = "flat_scope"
harness = false
12 changes: 1 addition & 11 deletions benches/bevy_tasks.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
//! Comparative benchmarks against bevy_tasks

struct BevyParChunks<'a, T>(core::slice::Chunks<'a, T>);
impl<'a, T> bevy_tasks::ParallelIterator<core::slice::Iter<'a, T>> for BevyParChunks<'a, T>
where
T: 'a + Send + Sync,
{
fn next_batch(&mut self) -> Option<core::slice::Iter<'a, T>> {
self.0.next().map(|s| s.iter())
}
}

struct BevyParChunksMut<'a, T>(core::slice::ChunksMut<'a, T>);
impl<'a, T> bevy_tasks::ParallelIterator<core::slice::IterMut<'a, T>> for BevyParChunksMut<'a, T>
where
Expand Down Expand Up @@ -97,7 +87,7 @@ mod overhead {

bencher.bench_local(|| {
THREAD_POOL.with_worker(|worker| {
forte_chunks::<100, _, _>(worker, &mut vec, &|c| {
forte_chunks::<8, _, _>(worker, &mut vec, &|c| {
c.iter_mut().for_each(work);
});
})
Expand Down
90 changes: 90 additions & 0 deletions benches/flat_scope.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//! A benchmark for fork-join workloads adapted from `chili`.

use std::hash::{DefaultHasher, Hash, Hasher};

use criterion::black_box;
use divan::Bencher;
use tracing_subscriber::fmt;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

const SIZES: &[usize] = &[8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4012, 8196];

fn sizes() -> impl Iterator<Item = usize> {
SIZES.iter().cloned()
}

// -----------------------------------------------------------------------------
// Benchmark

#[divan::bench(args = sizes(), threads = false)]
fn baseline(bencher: Bencher, size: usize) {
bencher.bench_local(move || {
for i in 0..size {
for j in 0..200 {
let mut s = DefaultHasher::new();
i.hash(&mut s);
j.hash(&mut s);
black_box(s.finish());
}
}
});
}

static COMPUTE: forte::ThreadPool = forte::ThreadPool::new();

#[divan::bench(args = sizes(), threads = false)]
fn forte(bencher: Bencher, size: usize) {
use forte::Worker;

COMPUTE.with_worker(|worker| {
bencher.bench_local(|| {
worker.scope(|scope| {
for i in 0..size {
scope.spawn_on(worker, move |_: &Worker| {
for j in 0..200 {
let mut s = DefaultHasher::new();
i.hash(&mut s);
j.hash(&mut s);
black_box(s.finish());
}
});
}
});
});
});
}

#[divan::bench(args = sizes(), threads = false)]
fn rayon(bencher: Bencher, size: usize) {
use rayon::scope;

bencher.bench_local(|| {
scope(|scope| {
for i in 0..size {
scope.spawn(move |_| {
for j in 0..200 {
let mut s = DefaultHasher::new();
i.hash(&mut s);
j.hash(&mut s);
black_box(s.finish());
}
});
}
});
});
}

fn main() {
let fmt_layer = fmt::layer()
.without_time()
.with_target(false)
.with_thread_names(true)
.compact();

tracing_subscriber::registry().with(fmt_layer).init();

COMPUTE.resize_to_available();

divan::main();
}
Loading