Skip to content

Commit cb73f2b

Browse files
authored
Merge pull request #11 from Milerius/feat/cpp-contenders
feat(bench): add rigtorp SPSCQueue C++ contender via FFI
2 parents e229eda + 0183205 commit cb73f2b

14 files changed

Lines changed: 872 additions & 48 deletions

File tree

‎.github/scripts/bench-report.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ normalize='
1919
elif .workload | startswith("general/") then "mantis/general"
2020
elif .workload | startswith("spsc/rtrb/") then "rtrb"
2121
elif .workload | startswith("spsc/crossbeam/") then "crossbeam"
22+
elif .workload | startswith("spsc/rigtorp/") then "rigtorp-cpp"
2223
else "other"
2324
end
2425
),

‎CLAUDE.md‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
## Quick Reference
44

5+
**Toolchain: nightly-only** (uses nightly features like `cold_path`). All build/test/lint commands use `cargo +nightly`.
6+
57
```
6-
Build: cargo build --features alloc,std
8+
Build: cargo +nightly build --features alloc,std
79
Build nightly: cargo +nightly build --all-features
8-
Test: cargo test --features alloc,std
10+
Test: cargo +nightly test --features alloc,std
911
Test nightly: cargo +nightly test --all-features
10-
Test no_std: cargo test -p mantis-core -p mantis-types -p mantis-queue --no-default-features
11-
Lint: cargo clippy --all-targets --features alloc,std -- -D warnings
12-
Lint nightly: cargo +nightly clippy --all-targets --all-features -- -D warnings
13-
Format: cargo fmt --all
14-
Format check: cargo fmt --all --check
12+
Test no_std: cargo +nightly test -p mantis-core -p mantis-types -p mantis-queue --no-default-features
13+
Lint: cargo +nightly clippy --all-targets --features alloc,std -- -D warnings
14+
Lint all: cargo +nightly clippy --all-targets --all-features -- -D warnings
15+
Format: cargo +nightly fmt --all
16+
Format check: cargo +nightly fmt --all --check
1517
Deny: cargo deny check
1618
Miri: cargo +nightly miri test -p mantis-queue
1719
Careful: cargo +nightly careful test

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/bench/Cargo.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ default = []
1212
asm = ["mantis-platform/asm"]
1313
perf-counters = ["mantis-platform/perf-counters"]
1414
bench-contenders = ["dep:rtrb", "dep:crossbeam-queue"]
15+
bench-contenders-cpp = ["dep:cc"]
1516

1617
[dependencies]
1718
mantis-core = { workspace = true }
@@ -24,6 +25,9 @@ serde_json = "1"
2425
rtrb = { version = "0.3", optional = true }
2526
crossbeam-queue = { version = "0.3", optional = true }
2627

28+
[build-dependencies]
29+
cc = { version = "1", optional = true }
30+
2731
[lints]
2832
workspace = true
2933

‎crates/bench/benches/spsc.rs‎

Lines changed: 202 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
//!
1010
//! Every implementation tests the same shapes for fair comparison:
1111
//!
12-
//! | Workload | u64 | msg48 | msg64 | inline | copy | rtrb | crossbeam |
13-
//! |---------------|-----|-------|-------|--------|------|------|-----------|
14-
//! | single | x | x | x | x | x | x | x |
15-
//! | burst_100 | x | x | x | x | x | x | x |
16-
//! | burst_1000 | x | x | x | x | x | x | x |
17-
//! | batch_100 | x | x | | | x | | |
18-
//! | batch_1000 | x | x | | | x | | |
19-
//! | full_drain | x | | | x | | | |
12+
//! | Workload | u64 | msg48 | msg64 | inline | copy | rtrb | crossbeam | rigtorp |
13+
//! |---------------|-----|-------|-------|--------|------|------|-----------|---------|
14+
//! | single | x | x | x | x | x | x | x | x |
15+
//! | burst_100 | x | x | x | x | x | x | x | x |
16+
//! | burst_1000 | x | x | x | x | x | x | x | x |
17+
//! | batch_100 | x | x | | | x | | | |
18+
//! | batch_1000 | x | x | | | x | | | |
19+
//! | full_drain | x | | | x | | | | |
2020
2121
use std::hint::black_box;
2222

@@ -743,6 +743,196 @@ fn bench_crossbeam_burst_1000(descs: &mut Vec<BenchDesc>, c: &mut MantisC) {
743743
#[cfg(not(feature = "bench-contenders"))]
744744
fn bench_contenders(_descs: &mut Vec<BenchDesc>, _c: &mut MantisC) {}
745745

746+
// ---------------------------------------------------------------------------
747+
// C++ contenders (behind feature flag)
748+
// ---------------------------------------------------------------------------
749+
750+
#[cfg(feature = "bench-contenders-cpp")]
751+
fn bench_cpp_contenders(descs: &mut Vec<BenchDesc>, c: &mut MantisC) {
752+
bench_rigtorp_single(descs, c);
753+
bench_rigtorp_burst(descs, c);
754+
}
755+
756+
#[cfg(feature = "bench-contenders-cpp")]
757+
fn bench_rigtorp_single(descs: &mut Vec<BenchDesc>, c: &mut MantisC) {
758+
use mantis_bench::rigtorp_ffi::{RigtorpMsg48, RigtorpMsg64, RigtorpU64};
759+
760+
descs.push(run_bench(
761+
c,
762+
"spsc/rigtorp/single_item/u64",
763+
"u64",
764+
1024,
765+
|b| {
766+
let mut q = RigtorpU64::new(1024);
767+
b.iter(|| {
768+
let _ = q.try_push(black_box(42u64));
769+
let _ = black_box(q.try_pop());
770+
});
771+
},
772+
));
773+
774+
descs.push(run_bench(
775+
c,
776+
"spsc/rigtorp/single_item/msg48",
777+
"Message48",
778+
1024,
779+
|b| {
780+
let mut q = RigtorpMsg48::new(1024);
781+
let msg = make_msg48(1);
782+
b.iter(|| {
783+
let _ = q.try_push(black_box(&msg));
784+
let _ = black_box(q.try_pop());
785+
});
786+
},
787+
));
788+
789+
descs.push(run_bench(
790+
c,
791+
"spsc/rigtorp/single_item/msg64",
792+
"Message64",
793+
1024,
794+
|b| {
795+
let mut q = RigtorpMsg64::new(1024);
796+
let msg = make_msg64(1);
797+
b.iter(|| {
798+
let _ = q.try_push(black_box(&msg));
799+
let _ = black_box(q.try_pop());
800+
});
801+
},
802+
));
803+
}
804+
805+
#[cfg(feature = "bench-contenders-cpp")]
806+
fn bench_rigtorp_burst(descs: &mut Vec<BenchDesc>, c: &mut MantisC) {
807+
bench_rigtorp_burst_100(descs, c);
808+
bench_rigtorp_burst_1000(descs, c);
809+
}
810+
811+
#[cfg(feature = "bench-contenders-cpp")]
812+
fn bench_rigtorp_burst_100(descs: &mut Vec<BenchDesc>, c: &mut MantisC) {
813+
use mantis_bench::rigtorp_ffi::{RigtorpMsg48, RigtorpMsg64, RigtorpU64};
814+
815+
descs.push(run_bench(
816+
c,
817+
"spsc/rigtorp/burst_100/u64",
818+
"u64",
819+
1024,
820+
|b| {
821+
let mut q = RigtorpU64::new(1024);
822+
b.iter(|| {
823+
for i in 0..100u64 {
824+
let _ = q.try_push(black_box(i));
825+
}
826+
for _ in 0..100 {
827+
let _ = black_box(q.try_pop());
828+
}
829+
});
830+
},
831+
));
832+
833+
descs.push(run_bench(
834+
c,
835+
"spsc/rigtorp/burst_100/msg48",
836+
"Message48",
837+
1024,
838+
|b| {
839+
let mut q = RigtorpMsg48::new(1024);
840+
let msgs: Vec<Message48> = (0..100).map(make_msg48).collect();
841+
b.iter(|| {
842+
for msg in &msgs {
843+
let _ = q.try_push(black_box(msg));
844+
}
845+
for _ in 0..100 {
846+
let _ = black_box(q.try_pop());
847+
}
848+
});
849+
},
850+
));
851+
852+
descs.push(run_bench(
853+
c,
854+
"spsc/rigtorp/burst_100/msg64",
855+
"Message64",
856+
1024,
857+
|b| {
858+
let mut q = RigtorpMsg64::new(1024);
859+
let msgs: Vec<Message64> = (0..100).map(make_msg64).collect();
860+
b.iter(|| {
861+
for msg in &msgs {
862+
let _ = q.try_push(black_box(msg));
863+
}
864+
for _ in 0..100 {
865+
let _ = black_box(q.try_pop());
866+
}
867+
});
868+
},
869+
));
870+
}
871+
872+
#[cfg(feature = "bench-contenders-cpp")]
873+
fn bench_rigtorp_burst_1000(descs: &mut Vec<BenchDesc>, c: &mut MantisC) {
874+
use mantis_bench::rigtorp_ffi::{RigtorpMsg48, RigtorpMsg64, RigtorpU64};
875+
876+
descs.push(run_bench(
877+
c,
878+
"spsc/rigtorp/burst_1000/u64",
879+
"u64",
880+
2048,
881+
|b| {
882+
let mut q = RigtorpU64::new(2048);
883+
b.iter(|| {
884+
for i in 0..1000u64 {
885+
let _ = q.try_push(black_box(i));
886+
}
887+
for _ in 0..1000 {
888+
let _ = black_box(q.try_pop());
889+
}
890+
});
891+
},
892+
));
893+
894+
descs.push(run_bench(
895+
c,
896+
"spsc/rigtorp/burst_1000/msg48",
897+
"Message48",
898+
2048,
899+
|b| {
900+
let mut q = RigtorpMsg48::new(2048);
901+
let msgs: Vec<Message48> = (0..1000).map(make_msg48).collect();
902+
b.iter(|| {
903+
for msg in &msgs {
904+
let _ = q.try_push(black_box(msg));
905+
}
906+
for _ in 0..1000 {
907+
let _ = black_box(q.try_pop());
908+
}
909+
});
910+
},
911+
));
912+
913+
descs.push(run_bench(
914+
c,
915+
"spsc/rigtorp/burst_1000/msg64",
916+
"Message64",
917+
2048,
918+
|b| {
919+
let mut q = RigtorpMsg64::new(2048);
920+
let msgs: Vec<Message64> = (0..1000).map(make_msg64).collect();
921+
b.iter(|| {
922+
for msg in &msgs {
923+
let _ = q.try_push(black_box(msg));
924+
}
925+
for _ in 0..1000 {
926+
let _ = black_box(q.try_pop());
927+
}
928+
});
929+
},
930+
));
931+
}
932+
933+
#[cfg(not(feature = "bench-contenders-cpp"))]
934+
fn bench_cpp_contenders(_descs: &mut Vec<BenchDesc>, _c: &mut MantisC) {}
935+
746936
// ---------------------------------------------------------------------------
747937
// Unified entry point
748938
// ---------------------------------------------------------------------------
@@ -753,6 +943,7 @@ fn bench_spsc(c: &mut MantisC) {
753943
bench_inline(&mut descs, c);
754944
bench_copy(&mut descs, c);
755945
bench_contenders(&mut descs, c);
946+
bench_cpp_contenders(&mut descs, c);
756947

757948
let mut features = Vec::new();
758949
if cfg!(feature = "asm") {
@@ -764,6 +955,9 @@ fn bench_spsc(c: &mut MantisC) {
764955
if cfg!(feature = "bench-contenders") {
765956
features.push("bench-contenders".to_owned());
766957
}
958+
if cfg!(feature = "bench-contenders-cpp") {
959+
features.push("bench-contenders-cpp".to_owned());
960+
}
767961
export_report(&descs, "SPSC Ring (all)", "spsc", features);
768962
}
769963

‎crates/bench/build.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![allow(missing_docs)]
2+
3+
fn main() {
4+
#[cfg(feature = "bench-contenders-cpp")]
5+
{
6+
cc::Build::new()
7+
.cpp(true)
8+
.std("c++17")
9+
.opt_level(3)
10+
.include("cpp/include")
11+
.file("cpp/rigtorp_ffi.cpp")
12+
.compile("rigtorp_ffi");
13+
}
14+
}

0 commit comments

Comments
 (0)