Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serde-brief to benchmarks #90

Merged
merged 5 commits into from
Nov 4, 2024
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
85 changes: 48 additions & 37 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[workspace]
members = [
"pages",
"tools/bencher",
"tools/formatter",
"tools/parser",
"tools/schema",
"pages",
"tools/bencher",
"tools/formatter",
"tools/parser",
"tools/schema",
]

[workspace.package]
Expand Down Expand Up @@ -50,7 +50,10 @@ bincode = { package = "bincode", version = "=2.0.0-rc.3", optional = true }
bitcode = { version = "=0.6.3", optional = true }
borsh = { version = "=1.5.1", features = ["derive"], optional = true }
capnp = { version = "=0.19.7", optional = true }
cbor4ii = { version = "=0.3.3", features = [ "use_std", "serde1" ], optional = true }
cbor4ii = { version = "=0.3.3", features = [
"use_std",
"serde1",
], optional = true }
ciborium = { version = "=0.2.2", optional = true }
criterion = "=0.5.1"
databuf = { version = "=0.5.0", optional = true }
Expand All @@ -59,8 +62,10 @@ flatbuffers = { version = "=24.3.25", optional = true }
libflate = "=2.1.0"
msgpacker = { version = "=0.4.3", optional = true }
nachricht-serde = { version = "=0.4.0", optional = true }
nanoserde = {version = "=0.1.37", optional = true }
parity-scale-codec = { version = "=3.6.12", features = ["full"], optional = true }
nanoserde = { version = "=0.1.37", optional = true }
parity-scale-codec = { version = "=3.6.12", features = [
"full",
], optional = true }
parity-scale-codec-derive = { version = "=3.6.12", optional = true }
postcard = { version = "=1.0.10", features = ["alloc"], optional = true }
pot = { version = "=3.0.1", optional = true }
Expand All @@ -72,8 +77,13 @@ rmp-serde = { version = "=1.3.0", optional = true }
ron = { version = "=0.8.1", optional = true }
serde = { version = "=1.0.210", features = ["derive"] }
serde_bare = { version = "=0.5.0", optional = true }
serde-brief = { version = "=0.1.0", features = [
"std",
], optional = true }
serde_cbor = { version = "=0.11.2", optional = true }
serde_json = { version = "=1.0.128", features = ["float_roundtrip"], optional = true }
serde_json = { version = "=1.0.128", features = [
"float_roundtrip",
], optional = true }
simd-json = { version = "=0.13.10", optional = true }
simd-json-derive = { version = "=0.13.0", optional = true }
speedy = { version = "=0.8.7", optional = true }
Expand All @@ -84,34 +94,35 @@ zstd = "=0.13.2"

[features]
default = [
"bilrost",
"bincode1",
"bincode",
"bitcode",
"borsh",
"capnp",
"cbor4ii",
"ciborium",
"databuf",
"dlhn",
"flatbuffers",
"msgpacker",
"nachricht-serde",
"nanoserde",
"scale",
"postcard",
"pot",
"prost",
"rkyv",
"rmp-serde",
"ron",
"serde_bare",
"serde_cbor",
"serde_json",
"simd-json",
"speedy",
"savefile",
"wiring"
"bilrost",
"bincode1",
"bincode",
"bitcode",
"borsh",
"capnp",
"cbor4ii",
"ciborium",
"databuf",
"dlhn",
"flatbuffers",
"msgpacker",
"nachricht-serde",
"nanoserde",
"scale",
"postcard",
"pot",
"prost",
"rkyv",
"rmp-serde",
"ron",
"serde_bare",
"serde-brief",
"serde_cbor",
"serde_json",
"simd-json",
"speedy",
"savefile",
"wiring",
]
capnp = ["dep:capnp"]
prost = ["dep:capnp", "dep:prost"]
Expand Down
14 changes: 14 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ use rust_serialization_benchmark::bench_ron;
use rust_serialization_benchmark::bench_savefile;
#[cfg(feature = "serde_bare")]
use rust_serialization_benchmark::bench_serde_bare;
#[cfg(feature = "serde-brief")]
use rust_serialization_benchmark::bench_serde_brief;
#[cfg(feature = "serde_cbor")]
use rust_serialization_benchmark::bench_serde_cbor;
#[cfg(feature = "serde_json")]
Expand Down Expand Up @@ -91,6 +93,9 @@ fn bench_log(c: &mut Criterion) {
#[cfg(feature = "borsh")]
bench_borsh::bench(BENCH, c, &data);

#[cfg(feature = "serde-brief")]
bench_serde_brief::bench(BENCH, c, &data);

#[cfg(feature = "capnp")]
bench_capnp::bench(BENCH, c, &data, |bytes| {
let message_reader =
Expand Down Expand Up @@ -268,6 +273,9 @@ fn bench_mesh(c: &mut Criterion) {
#[cfg(feature = "borsh")]
bench_borsh::bench(BENCH, c, &data);

#[cfg(feature = "serde-brief")]
bench_serde_brief::bench(BENCH, c, &data);

#[cfg(feature = "capnp")]
bench_capnp::bench(BENCH, c, &data, |bytes| {
let message_reader =
Expand Down Expand Up @@ -432,6 +440,9 @@ fn bench_minecraft_savedata(c: &mut Criterion) {
#[cfg(feature = "borsh")]
bench_borsh::bench(BENCH, c, &data);

#[cfg(feature = "serde-brief")]
bench_serde_brief::bench(BENCH, c, &data);

#[cfg(feature = "capnp")]
bench_capnp::bench(BENCH, c, &data, |bytes| {
let message_reader =
Expand Down Expand Up @@ -599,6 +610,9 @@ fn bench_mk48(c: &mut Criterion) {
#[cfg(feature = "borsh")]
bench_borsh::bench(BENCH, c, &data);

#[cfg(feature = "serde-brief")]
bench_serde_brief::bench(BENCH, c, &data);

#[cfg(feature = "capnp")]
bench_capnp::bench(BENCH, c, &data, |bytes| {
let message_reader =
Expand Down
11 changes: 3 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn capnpc_compile_dataset(name: &'static str) -> capnp::Result<()> {
let mut command = capnpc::CompilerCommand::new();
#[cfg(windows)]
command.capnp_executable("prebuilt/capnp.exe");
command.file(&format!("src/datasets/{0}/{0}.capnp", name));
command.file(format!("src/datasets/{0}/{0}.capnp", name));
command.output_path(".");
command.default_parent_module(vec!["datasets".into(), name.into()]);
command.run()
Expand All @@ -33,13 +33,8 @@ fn flatc_compile_dataset(name: &'static str) -> flatc_rust::Result<()> {

#[cfg(feature = "regenerate-prost")]
fn prost_compile_dataset(name: &'static str) -> std::io::Result<()> {
if cfg!(windows) {
match env::var("PROTOC") {
Err(_) => {
env::set_var("PROTOC", "./prebuilt/protoc.exe");
}
_ => {}
}
if cfg!(windows) && env::var("PROTOC").is_err() {
env::set_var("PROTOC", "./prebuilt/protoc.exe");
}
let mut prost_config = prost_build::Config::new();
prost_config.protoc_arg("--experimental_allow_proto3_optional");
Expand Down
35 changes: 35 additions & 0 deletions src/bench_serde_brief.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use criterion::{black_box, Criterion};
use serde::{Deserialize, Serialize};

pub fn bench<T>(name: &'static str, c: &mut Criterion, data: &T)
where
T: Serialize + for<'de> Deserialize<'de> + PartialEq,
{
const BUFFER_LEN: usize = 50_000_000;

let mut group = c.benchmark_group(format!("{}/serde-brief", name));

let mut serialize_buffer = vec![0; BUFFER_LEN];
group.bench_function("serialize", |b| {
b.iter(|| {
black_box(
serde_brief::to_slice(black_box(&data), black_box(serialize_buffer.as_mut_slice()))
.unwrap(),
);
})
});

let deserialize_buffer = serde_brief::to_vec(&data).unwrap();

group.bench_function("deserialize", |b| {
b.iter(|| {
black_box(serde_brief::from_slice::<'_, T>(black_box(&deserialize_buffer)).unwrap());
})
});

crate::bench_size(name, "serde-brief", deserialize_buffer.as_slice());

assert!(serde_brief::from_slice::<T>(&deserialize_buffer).unwrap() == *data);

group.finish();
}
3 changes: 1 addition & 2 deletions src/datasets/minecraft_savedata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use minecraft_savedata_prost as pb;
#[cfg(feature = "nanoserde")]
use nanoserde::{DeBin, SerBin};
use rand::Rng;
use rkyv::traits::NoUndef;
#[cfg(feature = "wiring")]
use wiring::prelude::{Unwiring, Wiring};

Expand Down Expand Up @@ -71,7 +70,7 @@ pub enum GameType {
}

#[cfg(feature = "rkyv")]
unsafe impl NoUndef for ArchivedGameType {}
unsafe impl rkyv::traits::NoUndef for ArchivedGameType {}

impl Generate for GameType {
fn generate<R: Rng>(rand: &mut R) -> Self {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub mod bench_ron;
pub mod bench_savefile;
#[cfg(feature = "serde_bare")]
pub mod bench_serde_bare;
#[cfg(feature = "serde-brief")]
pub mod bench_serde_brief;
#[cfg(feature = "serde_cbor")]
pub mod bench_serde_cbor;
#[cfg(feature = "serde_json")]
Expand Down
2 changes: 1 addition & 1 deletion tools/bencher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() {
};

let mut bench_path = PathBuf::from("benchmark_results");
bench_path.push(&format!(
bench_path.push(format!(
"{}-{}-{}_{}-{}-{}",
now.year(),
now.month() as usize,
Expand Down
5 changes: 2 additions & 3 deletions tools/formatter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn build_tables(
.collect::<Vec<_>>();

for (feature, crate_) in dataset.features.iter() {
if !columns.iter().all(|&c| crate_.benches.get(c).is_none()) {
if !columns.iter().all(|&c| crate_.benches.contains_key(c)) {
write_crate_row(&mut data, feature, features)?;
write_crate_row(&mut comparison, feature, features)?;

Expand Down Expand Up @@ -285,8 +285,7 @@ fn format(
let features = results
.datasets
.values()
.map(|dataset| dataset.features.keys())
.flatten()
.flat_map(|dataset| dataset.features.keys())
.collect::<BTreeSet<_>>();
for &feature in features.iter() {
write!(
Expand Down