Skip to content

Commit

Permalink
update bilrost to 0.1006.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mumbleskates committed Apr 13, 2024
1 parent d0328b2 commit b900fb6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 547 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ alkahest = { version = "=0.1.5", optional = true, features = [
"nightly",
] }
bebop = { version = "=2.8.7", optional = true }
bilrost = { version = "=0.1005.1", optional = true }
bilrost = { version = "=0.1006.0", 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.3", optional = true }
Expand Down
72 changes: 9 additions & 63 deletions src/bench_bilrost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,10 @@ use bilrost::buf::ReverseBuffer;
use bilrost::bytes::BufMut;
use bilrost::Message;
use criterion::{black_box, Criterion};
use std::borrow::Borrow;

pub trait ToBilrost: Sized {
type Message: Message + Into<Self>;
type Serializable<'a>: Borrow<Self::Message>
where
Self: 'a;

fn to_bilrost(&self) -> Self::Serializable<'_>;

fn is_already_bilrost() -> bool {
false // provided: false
}
}

impl<T> ToBilrost for T
where
T: Clone + Message,
{
type Message = Self;
type Serializable<'a> = &'a Self
where
Self: 'a;

fn to_bilrost(&self) -> &Self {
self
}

fn is_already_bilrost() -> bool {
true // true for this covering impl only
}
}

pub fn bench<T>(name: &'static str, c: &mut Criterion, data: &T)
where
T: ToBilrost + PartialEq,
T: Message + PartialEq,
{
const BUFFER_LEN: usize = 10_000_000;

Expand All @@ -46,61 +14,39 @@ where
let mut serialize_buffer = Vec::with_capacity(BUFFER_LEN);
let mut prepend_buffer = ReverseBuffer::with_capacity(BUFFER_LEN);

if !T::is_already_bilrost() {
group.bench_function("serialize (populate + encode)", |b| {
b.iter(|| {
black_box(&mut serialize_buffer).clear();
data.to_bilrost()
.borrow()
.encode(&mut serialize_buffer)
.unwrap();
black_box(());
})
});
group.bench_function("serialize (populate + prepend)", |b| {
b.iter(|| {
black_box(&mut prepend_buffer).clear();
data.to_bilrost().borrow().prepend(&mut prepend_buffer);
black_box(());
})
});
}

let message = data.to_bilrost();
group.bench_function("serialize (only encode)", |b| {
group.bench_function("serialize (encode)", |b| {
b.iter(|| {
black_box(&mut serialize_buffer).clear();
message.borrow().encode(&mut serialize_buffer).unwrap();
data.encode(&mut serialize_buffer).unwrap();
black_box(());
})
});

let message = data.to_bilrost();
group.bench_function("serialize (only prepend)", |b| {
group.bench_function("serialize (prepend)", |b| {
b.iter(|| {
black_box(&mut prepend_buffer).clear();
message.borrow().prepend(&mut prepend_buffer);
data.prepend(&mut prepend_buffer);
black_box(());
})
});

let mut deserialize_buffer = Vec::new();
message.borrow().encode(&mut deserialize_buffer).unwrap();
data.encode(&mut deserialize_buffer).unwrap();
let mut prepended_data = Vec::new();
prepended_data.put(message.borrow().encode_fast());
prepended_data.put(data.encode_fast());
// Because there are no unordered collections in the benchmarked types, we can assert that the
// prepended encoding path emits precisely the same bytes as the forward-encoded one.
assert_eq!(prepended_data, deserialize_buffer);

group.bench_function("deserialize", |b| {
b.iter(|| {
black_box(<T::Message>::decode(black_box(&deserialize_buffer).as_slice()).unwrap());
black_box(T::decode(black_box(&deserialize_buffer).as_slice()).unwrap());
})
});

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

assert!(<T::Message>::decode(&*deserialize_buffer).unwrap().into() == *data);
assert!(T::decode(&*deserialize_buffer).unwrap() == *data);

group.finish();
}
261 changes: 0 additions & 261 deletions src/datasets/minecraft_savedata/minecraft_savedata_bilrost.rs

This file was deleted.

Loading

0 comments on commit b900fb6

Please sign in to comment.