Skip to content

Commit

Permalink
Update bitcode (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
caibear committed Mar 1, 2024
1 parent 281e1df commit 9dd0173
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bebop = { version = "2.4.9", 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 }
bitcode = { version = "0.6.0-alpha.2", optional = true }
borsh = { version = "1.1.1", features = ["derive"], optional = true }
# TODO: Unfork after bson adds support for pre-warmed serialization buffers
# https://github.com/mongodb/bson-rust/pull/328
Expand Down
16 changes: 8 additions & 8 deletions src/bench_bitcode.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
use bitcode::{Decode, Encode};
use bitcode::{DecodeOwned, Encode};
use criterion::{black_box, Criterion};

pub fn bench<T>(name: &'static str, c: &mut Criterion, data: &T)
where
T: Encode + Decode,
T: Encode + DecodeOwned,
{
let mut group = c.benchmark_group(format!("{}/bitcode", name));
let mut buffer = bitcode::Buffer::with_capacity(10000000);
let mut buffer = bitcode::EncodeBuffer::<T>::default();

group.bench_function("serialize", |b| {
b.iter(|| {
buffer.encode(black_box(&data)).unwrap();
black_box(());
black_box(buffer.encode(black_box(data)));
})
});

let encoded = bitcode::encode(&data).unwrap();
let encoded = buffer.encode(data);
let mut buffer = bitcode::DecodeBuffer::<T>::default();

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

crate::bench_size(name, "bitcode", encoded.as_slice());
crate::bench_size(name, "bitcode", encoded);

group.finish();
}
2 changes: 0 additions & 2 deletions src/datasets/log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ pub struct Log {
pub userid: String,
pub date: String,
pub request: String,
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "100..599"))]
pub code: u16,
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..100000000"))]
pub size: u64,
}

Expand Down
1 change: 0 additions & 1 deletion src/datasets/mesh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use crate::Generate;
#[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(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
Expand Down
10 changes: 0 additions & 10 deletions src/datasets/minecraft_savedata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,7 @@ impl alkahest::Pack<ItemSchema> for &'_ Item {
#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))]
#[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))]
pub struct Abilities {
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))]
pub walk_speed: f32,
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))]
pub fly_speed: f32,
pub may_fly: bool,
pub flying: bool,
Expand Down Expand Up @@ -442,13 +440,9 @@ impl alkahest::Pack<Abilities> for Abilities {
#[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))]
pub struct Entity {
pub id: String,
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))]
pub pos: (f64, f64, f64),
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))]
pub motion: (f64, f64, f64),
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))]
pub rotation: (f32, f32),
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))]
pub fall_distance: f32,
pub fire: u16,
pub air: u16,
Expand Down Expand Up @@ -988,20 +982,16 @@ pub struct Player {
pub spawn_z: i64,
pub spawn_forced: Option<bool>,
pub sleep_timer: u16,
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))]
pub food_exhaustion_level: f32,
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))]
pub food_saturation_level: f32,
pub food_tick_timer: u32,
pub xp_level: u32,
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))]
pub xp_p: f32,
pub xp_total: i32,
pub xp_seed: i32,
pub inventory: Vec<Item>,
pub ender_items: Vec<Item>,
pub abilities: Abilities,
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))]
pub entered_nether_position: Option<(f64, f64, f64)>,
pub root_vehicle: Option<([u32; 4], Entity)>,
pub shoulder_entity_left: Option<Entity>,
Expand Down
16 changes: 0 additions & 16 deletions src/datasets/mk48/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,15 @@ use crate::{generate_vec, Generate};
#[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))]
#[repr(u8)]
pub enum EntityType {
#[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 2.14))]
ArleighBurke,
#[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 0.52))]
Bismarck,
#[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 0.97))]
Clemenceau,
#[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 1.46))]
Fletcher,
#[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 13.16))]
G5,
#[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 1.55))]
Iowa,
#[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 0.83))]
Kolkata,
#[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 7.25))]
Osa,
#[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 4.06))]
Yasen,
#[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 12.92))]
Zubr,
}

Expand Down Expand Up @@ -312,7 +302,6 @@ fn generate_velocity(rng: &mut impl Rng) -> i16 {
#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))]
#[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))]
pub struct Transform {
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..1"))]
pub altitude: i8,
pub angle: u16,
pub position: (f32, f32),
Expand Down Expand Up @@ -543,13 +532,10 @@ impl alkahest::Pack<Guidance> for Guidance {
#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))]
#[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))]
pub struct Contact {
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..1"))]
pub damage: u8,
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..8000"))]
pub entity_id: u32,
pub entity_type: Option<EntityType>,
pub guidance: Guidance,
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..400"))]
pub player_id: Option<u16>,
pub reloads: Vec<bool>,
pub transform: Transform,
Expand Down Expand Up @@ -771,7 +757,6 @@ impl alkahest::Pack<ContactSchema> for &'_ Contact {
#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))]
#[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))]
pub struct TerrainUpdate {
#[cfg_attr(feature = "bitcode", bitcode_hint(gamma))]
chunk_id: (i8, i8),
data: Vec<u8>,
}
Expand Down Expand Up @@ -913,7 +898,6 @@ impl alkahest::Pack<TerrainUpdateSchema> for &'_ TerrainUpdate {
#[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))]
pub struct Update {
pub contacts: Vec<Contact>,
#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..5000"))]
pub score: u32,
pub world_radius: f32,
pub terrain_updates: Vec<TerrainUpdate>,
Expand Down

0 comments on commit 9dd0173

Please sign in to comment.