Skip to content

Commit

Permalink
Added Bincode2 (#61)
Browse files Browse the repository at this point in the history
* Added bincode 2 as own benchmark

* All bincode2 benchmarks running

* Add support for multiple versions of a package

---------

Co-authored-by: 8192K <sebastian@frehmel.de>
Co-authored-by: David Koloski <djkoloski@gmail.com>
  • Loading branch information
3 people authored Jan 6, 2024
1 parent e1f6a31 commit 7e8543c
Show file tree
Hide file tree
Showing 19 changed files with 217 additions and 89 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ alkahest = { version = "0.1.5", optional = true, features = [
"nightly",
] }
bebop = { version = "2.4.9", optional = true }
bincode = { version = "1.3.3", optional = true }
bincode1 = {package = "bincode", version = "1.3.3", optional = true }
# Can't call it bincode2 because of a current issue of bincode2
bincode = {package = "bincode", version = "2.0.0-rc", optional = true }
bitcode = { version = "0.5.0", optional = true }
borsh = { version = "1.1.1", features = ["derive"], optional = true }
# TODO: Unfork after bson adds support for pre-warmed serialization buffers
Expand Down Expand Up @@ -95,6 +97,7 @@ default = [
"abomonation_derive",
"alkahest",
# "bebop",
"bincode1",
"bincode",
"bitcode",
"borsh",
Expand Down
14 changes: 14 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use rust_serialization_benchmark::bench_abomonation;
use rust_serialization_benchmark::bench_alkahest;
#[cfg(feature = "bincode")]
use rust_serialization_benchmark::bench_bincode;
#[cfg(feature = "bincode1")]
use rust_serialization_benchmark::bench_bincode1;
#[cfg(feature = "bitcode")]
use rust_serialization_benchmark::bench_bitcode;
#[cfg(feature = "borsh")]
Expand Down Expand Up @@ -94,6 +96,9 @@ fn bench_log(c: &mut Criterion) {
}
});

#[cfg(feature = "bincode1")]
bench_bincode1::bench(BENCH, c, &data);

#[cfg(feature = "bincode")]
bench_bincode::bench(BENCH, c, &data);

Expand Down Expand Up @@ -265,6 +270,9 @@ fn bench_mesh(c: &mut Criterion) {
}
});

#[cfg(feature = "bincode1")]
bench_bincode1::bench(BENCH, c, &data);

#[cfg(feature = "bincode")]
bench_bincode::bench(BENCH, c, &data);

Expand Down Expand Up @@ -420,6 +428,9 @@ fn bench_minecraft_savedata(c: &mut Criterion) {
}
});

#[cfg(feature = "bincode1")]
bench_bincode1::bench(BENCH, c, &data);

#[cfg(feature = "bincode")]
bench_bincode::bench(BENCH, c, &data);

Expand Down Expand Up @@ -579,6 +590,9 @@ fn bench_mk48(c: &mut Criterion) {
}
});

#[cfg(feature = "bincode1")]
bench_bincode1::bench(BENCH, c, &data);

#[cfg(feature = "bincode")]
bench_bincode::bench(BENCH, c, &data);

Expand Down
8 changes: 4 additions & 4 deletions pages/src/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Display for Bottleneck {

pub struct CalcRow {
pub compression: Compression,
pub crate_: String,
pub feature: String,
pub limit: Bottleneck,
pub messages_per_second: f32,
pub relative: f32,
Expand All @@ -50,7 +50,7 @@ pub fn calc(
})
.flat_map(|(r, deserialize)| {
let Row {
crate_,
feature,
serialize,
sizes,
..
Expand Down Expand Up @@ -83,7 +83,7 @@ pub fn calc(
};
CalcRow {
compression,
crate_: crate_.clone(),
feature: feature.clone(),
limit,
messages_per_second: benchmarks_per_second * messages_per_benchmark as f32,
relative: 0.0,
Expand All @@ -108,7 +108,7 @@ pub fn calc(

// Dedup crates.
let mut seen = HashSet::new();
rows.retain(|r| seen.insert(r.crate_.clone()));
rows.retain(|r| seen.insert(r.feature.clone()));

rows
}
4 changes: 2 additions & 2 deletions pages/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn benchmark() -> Html {
.datasets
.get(&dataset)
.unwrap()
.crates
.features
.iter()
.map(TryFrom::try_from)
.collect();
Expand Down Expand Up @@ -258,7 +258,7 @@ fn benchmark() -> Html {
rows.iter().map(|row| {
html! {
<tr>
<td><a href={format!("https://crates.io/crates/{}/{}", row.crate_, results.meta.crate_versions.get(&row.crate_).unwrap())} target="_blank">{ &row.crate_ }</a></td>
<td><a href={results.features.get(&row.feature).unwrap().crates_io_url()} target="_blank">{ &row.feature }</a></td>
<td> { row.compression.to_string() } </td>
<td> { format_float(row.messages_per_second, 3) } </td>
<td> { format!("{}%", (row.relative * 100.0) as u32) } </td>
Expand Down
10 changes: 5 additions & 5 deletions pages/src/row.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::compression::{Compression, CompressionMap};
use schema::{Bench, Crate};
use schema::{Bench, Feature};

#[derive(Debug)]
pub struct Row {
pub crate_: String,
pub feature: String,
pub serialize: f32,
pub deserialize: Option<f32>,
pub sizes: CompressionMap<u64>,
Expand All @@ -26,10 +26,10 @@ fn unwrap_seconds(bench: &Bench) -> Result<Option<f64>> {
}
}

impl TryFrom<(&String, &Crate)> for Row {
impl TryFrom<(&String, &Feature)> for Row {
type Error = Error;

fn try_from((crate_, Crate { benches }): (&String, &Crate)) -> Result<Self> {
fn try_from((feature, Feature { benches }): (&String, &Feature)) -> Result<Self> {
let col = |key: &'static str| -> Result<&Bench> { benches.get(key).ok_or(key) };

let serialize = unwrap_seconds(col("serialize")?)?.ok_or("no serialize primary")? as f32;
Expand All @@ -44,7 +44,7 @@ impl TryFrom<(&String, &Crate)> for Row {
sizes.insert(Compression::Zstd, unwrap_bytes(col("zstd")?)?);

Ok(Self {
crate_: crate_.clone(),
feature: feature.clone(),
serialize,
deserialize,
sizes,
Expand Down
23 changes: 13 additions & 10 deletions src/bench_bincode.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
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>,
T: bincode::Encode + bincode::Decode,
{
const BUFFER_LEN: usize = 10_000_000;

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

let mut serialize_buffer = vec![0; BUFFER_LEN];
let mut buffer = Box::new([0u8; BUFFER_LEN]);
let conf = bincode::config::standard();
group.bench_function("serialize", |b| {
b.iter(|| {
bincode::serialize_into(black_box(serialize_buffer.as_mut_slice()), black_box(&data))
let size = bincode::encode_into_slice(black_box(&data), black_box(&mut *buffer), conf)
.unwrap();
black_box(());
black_box(&buffer[..size]);
})
});

let mut deserialize_buffer = Vec::new();
bincode::serialize_into(&mut deserialize_buffer, &data).unwrap();
let size = bincode::encode_into_slice(&data, &mut *buffer, conf).unwrap();
let buffer = &buffer[..size];

group.bench_function("deserialize", |b| {
b.iter(|| {
black_box(bincode::deserialize::<'_, T>(black_box(&deserialize_buffer)).unwrap());
black_box(
bincode::decode_from_slice::<T, _>(black_box(buffer), conf)
.unwrap()
.0,
);
})
});

crate::bench_size(name, "bincode", deserialize_buffer.as_slice());
crate::bench_size(name, "bincode", buffer);

group.finish();
}
33 changes: 33 additions & 0 deletions src/bench_bincode1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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>,
{
const BUFFER_LEN: usize = 10_000_000;

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

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

let mut deserialize_buffer = Vec::new();
bincode1::serialize_into(&mut deserialize_buffer, &data).unwrap();

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

crate::bench_size(name, "bincode1", deserialize_buffer.as_slice());

group.finish();
}
3 changes: 3 additions & 0 deletions src/datasets/log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::Generate;

#[derive(Clone, Copy)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -129,6 +130,7 @@ impl alkahest::Pack<Address> for Address {

#[derive(Clone)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -338,6 +340,7 @@ impl alkahest::Pack<LogSchema> for &'_ Log {

#[derive(Clone)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down
3 changes: 3 additions & 0 deletions src/datasets/mesh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::Generate;

#[derive(Clone, Copy)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))]
#[cfg_attr(
Expand Down Expand Up @@ -123,6 +124,7 @@ impl alkahest::Pack<Vector3> for Vector3 {

#[derive(Clone, Copy)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -225,6 +227,7 @@ impl alkahest::Pack<Triangle> for &'_ Triangle {

#[derive(Clone)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down
7 changes: 7 additions & 0 deletions src/datasets/minecraft_savedata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::{generate_vec, Generate};

#[derive(Clone, Copy)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -132,6 +133,7 @@ impl alkahest::Pack<GameType> for GameType {

#[derive(Clone)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -253,6 +255,7 @@ impl alkahest::Pack<ItemSchema> for &'_ Item {

#[derive(Clone, Copy)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -374,6 +377,7 @@ impl alkahest::Pack<Abilities> for Abilities {

#[derive(Clone)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -639,6 +643,7 @@ impl alkahest::Pack<EntitySchema> for &'_ Entity {

#[derive(Clone)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -844,6 +849,7 @@ impl alkahest::Pack<RecipeBookSchema> for &'_ RecipeBook {

#[derive(Clone)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -1294,6 +1300,7 @@ impl alkahest::Pack<PlayerSchema> for &'_ Player {

#[derive(Clone)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down
7 changes: 7 additions & 0 deletions src/datasets/mk48/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use crate::{generate_vec, Generate};

#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -266,6 +267,7 @@ fn generate_velocity(rng: &mut impl Rng) -> i16 {

#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -375,6 +377,7 @@ impl alkahest::Pack<Transform> for Transform {

#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -466,6 +469,7 @@ impl alkahest::Pack<Guidance> for Guidance {

#[derive(Clone, Debug)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -671,6 +675,7 @@ impl alkahest::Pack<ContactSchema> for &'_ Contact {

#[derive(Clone, Debug)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -794,6 +799,7 @@ impl alkahest::Pack<TerrainUpdateSchema> for &'_ TerrainUpdate {

#[derive(Clone, Debug)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -950,6 +956,7 @@ impl alkahest::Pack<UpdateSchema> for &'_ Update {

#[derive(Clone)]
#[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "borsh",
Expand Down
Loading

0 comments on commit 7e8543c

Please sign in to comment.