From 4cd95c06534cfc4d99c7eec6b860661593223306 Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Wed, 12 Jul 2023 22:22:02 +0200 Subject: [PATCH 1/3] Add support for 'Savefile'-serialization framework --- Cargo.toml | 5 ++++ benches/bench.rs | 16 ++++++++++++- src/bench_savefile.rs | 33 ++++++++++++++++++++++++++ src/datasets/log/mod.rs | 6 +++++ src/datasets/mesh/mod.rs | 6 +++++ src/datasets/minecraft_savedata/mod.rs | 9 +++++++ src/datasets/mk48/mod.rs | 9 +++++++ src/lib.rs | 2 ++ 8 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/bench_savefile.rs diff --git a/Cargo.toml b/Cargo.toml index fdc5998..778b17d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,6 +74,8 @@ serde_json = { version = "1.0.96", optional = true } simd-json = { version = "0.9.2", optional = true } simd-json-derive = { version = "0.9.2", optional = true } speedy = { version = "0.8.6", optional = true } +savefile = { version = "0.13", optional = true } +savefile-derive = { version = "0.13", optional = true } zstd = "0.12.3" [features] @@ -107,9 +109,12 @@ default = [ "serde_json", "simd-json", "speedy", + "savefile" ] simd-json = ["dep:simd-json", "simd-json-derive"] +savefile = ["dep:savefile", "savefile-derive"] + scale = ["parity-scale-codec", "parity-scale-codec-derive"] [dev-dependencies] diff --git a/benches/bench.rs b/benches/bench.rs index 5035fc6..4c18102 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -46,7 +46,9 @@ use rust_serialization_benchmark::bench_serde_json; use rust_serialization_benchmark::bench_simd_json; #[cfg(feature = "speedy")] use rust_serialization_benchmark::bench_speedy; -use rust_serialization_benchmark::generate_vec; +#[cfg(feature = "savefile")] +use rust_serialization_benchmark::bench_savefile; +use rust_serialization_benchmark::{generate_vec}; fn bench_log(c: &mut Criterion) { use rust_serialization_benchmark::datasets::log::{Log, Logs}; @@ -206,6 +208,9 @@ fn bench_log(c: &mut Criterion) { #[cfg(feature = "speedy")] bench_speedy::bench(BENCH, c, &data); + + #[cfg(feature = "savefile")] + bench_savefile::bench(BENCH, c, &data); } fn bench_mesh(c: &mut Criterion) { @@ -347,6 +352,9 @@ fn bench_mesh(c: &mut Criterion) { #[cfg(feature = "speedy")] bench_speedy::bench(BENCH, c, &data); + + #[cfg(feature = "savefile")] + bench_savefile::bench(BENCH, c, &data); } fn bench_minecraft_savedata(c: &mut Criterion) { @@ -491,6 +499,9 @@ fn bench_minecraft_savedata(c: &mut Criterion) { #[cfg(feature = "speedy")] bench_speedy::bench(BENCH, c, &data); + + #[cfg(feature = "savefile")] + bench_savefile::bench(BENCH, c, &data); } fn bench_mk48(c: &mut Criterion) { @@ -631,6 +642,9 @@ fn bench_mk48(c: &mut Criterion) { #[cfg(feature = "speedy")] bench_speedy::bench(BENCH, c, &data); + + #[cfg(feature = "savefile")] + bench_savefile::bench(BENCH, c, &data); } pub fn criterion_benchmark(c: &mut Criterion) { diff --git a/src/bench_savefile.rs b/src/bench_savefile.rs new file mode 100644 index 0000000..a11f843 --- /dev/null +++ b/src/bench_savefile.rs @@ -0,0 +1,33 @@ +use std::io::Cursor; +use criterion::{black_box, Criterion}; +use savefile::{Deserialize, Serialize, WithSchema}; + +pub fn bench(name: &'static str, c: &mut Criterion, data: &T) +where + T: Serialize + Deserialize + WithSchema +{ + let mut group = c.benchmark_group(format!("{}/savefile", name)); + + let mut serialize_buffer = Vec::new(); + group.bench_function("serialize", |b| { + b.iter(|| { + serialize_buffer.clear(); + savefile::save_noschema(black_box(&mut serialize_buffer), 0, black_box(data)).unwrap(); + black_box(()); + }) + }); + + let mut deserialize_buffer = Vec::new(); + savefile::save_noschema(&mut deserialize_buffer, 0, data).unwrap(); + + group.bench_function("deserialize", |b| { + b.iter(|| { + let mut reader = Cursor::new(&deserialize_buffer); + black_box(savefile::load_noschema::(black_box(&mut reader), 0).unwrap()); + }) + }); + + crate::bench_size(name, "savefile", deserialize_buffer.as_slice()); + + group.finish(); +} diff --git a/src/datasets/log/mod.rs b/src/datasets/log/mod.rs index 9928384..e705722 100644 --- a/src/datasets/log/mod.rs +++ b/src/datasets/log/mod.rs @@ -29,6 +29,9 @@ use crate::bench_flatbuffers; use crate::bench_prost; use crate::Generate; +#[cfg(feature = "savefile")] +use savefile::prelude::ReprC; + #[derive(Clone, Copy)] #[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))] #[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))] @@ -53,6 +56,7 @@ use crate::Generate; )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::ReprC, savefile_derive::Savefile), repr(C))] pub struct Address { pub x0: u8, pub x1: u8, @@ -145,6 +149,7 @@ impl alkahest::Pack
for Address { derive(parity_scale_codec_derive::Encode, parity_scale_codec_derive::Decode) )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Log { pub address: Address, pub identity: String, @@ -349,6 +354,7 @@ impl alkahest::Pack for &'_ Log { derive(parity_scale_codec_derive::Encode, parity_scale_codec_derive::Decode) )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Logs { pub logs: Vec, } diff --git a/src/datasets/mesh/mod.rs b/src/datasets/mesh/mod.rs index 6c105c5..819dd69 100644 --- a/src/datasets/mesh/mod.rs +++ b/src/datasets/mesh/mod.rs @@ -27,6 +27,9 @@ use crate::bench_flatbuffers; use crate::bench_prost; use crate::Generate; +#[cfg(feature = "savefile")] +use savefile::prelude::ReprC; + #[derive(Clone, Copy)] #[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))] #[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))] @@ -52,6 +55,7 @@ use crate::Generate; )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::ReprC, savefile_derive::Savefile), repr(C))] pub struct Vector3 { pub x: f32, pub y: f32, @@ -140,6 +144,7 @@ impl alkahest::Pack for Vector3 { )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::ReprC, savefile_derive::Savefile), repr(C))] pub struct Triangle { pub v0: Vector3, pub v1: Vector3, @@ -238,6 +243,7 @@ impl alkahest::Pack for &'_ Triangle { derive(simd_json_derive::Serialize, simd_json_derive::Deserialize) )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Mesh { pub triangles: Vec, } diff --git a/src/datasets/minecraft_savedata/mod.rs b/src/datasets/minecraft_savedata/mod.rs index 4344e56..6cc27b4 100644 --- a/src/datasets/minecraft_savedata/mod.rs +++ b/src/datasets/minecraft_savedata/mod.rs @@ -28,6 +28,8 @@ use crate::bench_flatbuffers; #[cfg(feature = "prost")] use crate::bench_prost; use crate::{generate_vec, Generate}; +#[cfg(feature = "savefile")] +use savefile::prelude::ReprC; #[derive(Clone, Copy)] #[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))] @@ -53,6 +55,7 @@ use crate::{generate_vec, Generate}; )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::ReprC, savefile_derive::Savefile))] #[repr(u8)] pub enum GameType { Survival, @@ -148,6 +151,7 @@ impl alkahest::Pack for GameType { derive(simd_json_derive::Serialize, simd_json_derive::Deserialize) )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Item { pub count: i8, pub slot: u8, @@ -265,6 +269,7 @@ impl alkahest::Pack for &'_ Item { )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::ReprC, savefile_derive::Savefile), repr(C))] pub struct Abilities { #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] pub walk_speed: f32, @@ -382,6 +387,7 @@ impl alkahest::Pack for Abilities { derive(simd_json_derive::Serialize, simd_json_derive::Deserialize) )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Entity { pub id: String, #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] @@ -642,6 +648,7 @@ impl alkahest::Pack for &'_ Entity { derive(simd_json_derive::Serialize, simd_json_derive::Deserialize) )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct RecipeBook { pub recipes: Vec, pub to_be_displayed: Vec, @@ -842,6 +849,7 @@ impl alkahest::Pack for &'_ RecipeBook { derive(simd_json_derive::Serialize, simd_json_derive::Deserialize) )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Player { pub game_type: GameType, pub previous_game_type: GameType, @@ -1287,6 +1295,7 @@ impl alkahest::Pack for &'_ Player { derive(simd_json_derive::Serialize, simd_json_derive::Deserialize) )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Players { pub players: Vec, } diff --git a/src/datasets/mk48/mod.rs b/src/datasets/mk48/mod.rs index c8097fe..ac7af5d 100644 --- a/src/datasets/mk48/mod.rs +++ b/src/datasets/mk48/mod.rs @@ -30,6 +30,8 @@ use crate::bench_flatbuffers; #[cfg(feature = "prost")] use crate::bench_prost; use crate::{generate_vec, Generate}; +#[cfg(feature = "savefile")] +use savefile::prelude::ReprC; #[derive(Copy, Clone, Debug)] #[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))] @@ -55,6 +57,7 @@ use crate::{generate_vec, Generate}; )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::ReprC, savefile_derive::Savefile))] #[repr(u8)] pub enum EntityType { #[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 2.14))] @@ -283,6 +286,7 @@ fn generate_velocity(rng: &mut impl Rng) -> i16 { )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Transform { #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..1"))] pub altitude: i8, @@ -389,6 +393,7 @@ impl alkahest::Pack for Transform { )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Guidance { pub angle: u16, pub submerge: bool, @@ -476,6 +481,7 @@ impl alkahest::Pack for Guidance { derive(simd_json_derive::Serialize, simd_json_derive::Deserialize) )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Contact { #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..1"))] pub damage: u8, @@ -678,6 +684,7 @@ impl alkahest::Pack for &'_ Contact { derive(simd_json_derive::Serialize, simd_json_derive::Deserialize) )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct TerrainUpdate { #[cfg_attr(feature = "bitcode", bitcode_hint(gamma))] chunk_id: (i8, i8), @@ -798,6 +805,7 @@ impl alkahest::Pack for &'_ TerrainUpdate { derive(simd_json_derive::Serialize, simd_json_derive::Deserialize) )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Update { pub contacts: Vec, #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..5000"))] @@ -951,6 +959,7 @@ impl alkahest::Pack for &'_ Update { derive(simd_json_derive::Serialize, simd_json_derive::Deserialize) )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Updates { pub updates: Vec, } diff --git a/src/lib.rs b/src/lib.rs index 3f0e11f..62919d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,6 +44,8 @@ pub mod bench_serde_json; pub mod bench_simd_json; #[cfg(feature = "speedy")] pub mod bench_speedy; +#[cfg(feature = "savefile")] +pub mod bench_savefile; pub mod datasets; use core::{mem, ops}; From 32e1a5874097bf344a3e2f4562d175b7ca40f268 Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Thu, 13 Jul 2023 01:11:30 +0200 Subject: [PATCH 2/3] Update to savefile 0.14 --- Cargo.toml | 4 ++-- src/datasets/log/mod.rs | 5 +---- src/datasets/mesh/mod.rs | 7 ++----- src/datasets/minecraft_savedata/mod.rs | 6 ++---- src/datasets/mk48/mod.rs | 4 +--- 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 778b17d..e2f9fd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,8 +74,8 @@ serde_json = { version = "1.0.96", optional = true } simd-json = { version = "0.9.2", optional = true } simd-json-derive = { version = "0.9.2", optional = true } speedy = { version = "0.8.6", optional = true } -savefile = { version = "0.13", optional = true } -savefile-derive = { version = "0.13", optional = true } +savefile = { version = "0.14", optional = true } +savefile-derive = { version = "0.14", optional = true } zstd = "0.12.3" [features] diff --git a/src/datasets/log/mod.rs b/src/datasets/log/mod.rs index e705722..fe2a881 100644 --- a/src/datasets/log/mod.rs +++ b/src/datasets/log/mod.rs @@ -29,9 +29,6 @@ use crate::bench_flatbuffers; use crate::bench_prost; use crate::Generate; -#[cfg(feature = "savefile")] -use savefile::prelude::ReprC; - #[derive(Clone, Copy)] #[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))] #[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))] @@ -56,7 +53,7 @@ use savefile::prelude::ReprC; )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] -#[cfg_attr(feature = "savefile", derive(savefile_derive::ReprC, savefile_derive::Savefile), repr(C))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile), savefile_unsafe_and_fast, repr(C))] pub struct Address { pub x0: u8, pub x1: u8, diff --git a/src/datasets/mesh/mod.rs b/src/datasets/mesh/mod.rs index 819dd69..dd69295 100644 --- a/src/datasets/mesh/mod.rs +++ b/src/datasets/mesh/mod.rs @@ -27,9 +27,6 @@ use crate::bench_flatbuffers; use crate::bench_prost; use crate::Generate; -#[cfg(feature = "savefile")] -use savefile::prelude::ReprC; - #[derive(Clone, Copy)] #[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))] #[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))] @@ -55,7 +52,7 @@ use savefile::prelude::ReprC; )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] -#[cfg_attr(feature = "savefile", derive(savefile_derive::ReprC, savefile_derive::Savefile), repr(C))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile), savefile_unsafe_and_fast, repr(C))] pub struct Vector3 { pub x: f32, pub y: f32, @@ -144,7 +141,7 @@ impl alkahest::Pack for Vector3 { )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] -#[cfg_attr(feature = "savefile", derive(savefile_derive::ReprC, savefile_derive::Savefile), repr(C))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile), savefile_unsafe_and_fast, repr(C))] pub struct Triangle { pub v0: Vector3, pub v1: Vector3, diff --git a/src/datasets/minecraft_savedata/mod.rs b/src/datasets/minecraft_savedata/mod.rs index 6cc27b4..f770b33 100644 --- a/src/datasets/minecraft_savedata/mod.rs +++ b/src/datasets/minecraft_savedata/mod.rs @@ -28,8 +28,6 @@ use crate::bench_flatbuffers; #[cfg(feature = "prost")] use crate::bench_prost; use crate::{generate_vec, Generate}; -#[cfg(feature = "savefile")] -use savefile::prelude::ReprC; #[derive(Clone, Copy)] #[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))] @@ -55,7 +53,7 @@ use savefile::prelude::ReprC; )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] -#[cfg_attr(feature = "savefile", derive(savefile_derive::ReprC, savefile_derive::Savefile))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile), savefile_unsafe_and_fast)] #[repr(u8)] pub enum GameType { Survival, @@ -269,7 +267,7 @@ impl alkahest::Pack for &'_ Item { )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] -#[cfg_attr(feature = "savefile", derive(savefile_derive::ReprC, savefile_derive::Savefile), repr(C))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Abilities { #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] pub walk_speed: f32, diff --git a/src/datasets/mk48/mod.rs b/src/datasets/mk48/mod.rs index ac7af5d..8b1e708 100644 --- a/src/datasets/mk48/mod.rs +++ b/src/datasets/mk48/mod.rs @@ -30,8 +30,6 @@ use crate::bench_flatbuffers; #[cfg(feature = "prost")] use crate::bench_prost; use crate::{generate_vec, Generate}; -#[cfg(feature = "savefile")] -use savefile::prelude::ReprC; #[derive(Copy, Clone, Debug)] #[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))] @@ -57,7 +55,7 @@ use savefile::prelude::ReprC; )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] -#[cfg_attr(feature = "savefile", derive(savefile_derive::ReprC, savefile_derive::Savefile))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile), savefile_unsafe_and_fast)] #[repr(u8)] pub enum EntityType { #[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 2.14))] From f4def3d180faacbb1c3fc672c9dcf50bcc8029f3 Mon Sep 17 00:00:00 2001 From: David Koloski Date: Thu, 13 Jul 2023 10:52:37 -0400 Subject: [PATCH 3/3] Format, alphabetize bench, remove unsafe --- benches/bench.rs | 30 +++++++++++++------------- src/bench_savefile.rs | 4 ++-- src/datasets/log/mod.rs | 2 +- src/datasets/mesh/mod.rs | 4 ++-- src/datasets/minecraft_savedata/mod.rs | 3 +-- src/datasets/mk48/mod.rs | 3 +-- src/lib.rs | 4 ++-- 7 files changed, 24 insertions(+), 26 deletions(-) diff --git a/benches/bench.rs b/benches/bench.rs index 4c18102..14be5d7 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -36,6 +36,8 @@ use rust_serialization_benchmark::bench_rkyv; use rust_serialization_benchmark::bench_rmp_serde; #[cfg(feature = "ron")] use rust_serialization_benchmark::bench_ron; +#[cfg(feature = "savefile")] +use rust_serialization_benchmark::bench_savefile; #[cfg(feature = "serde_bare")] use rust_serialization_benchmark::bench_serde_bare; #[cfg(feature = "serde_cbor")] @@ -46,9 +48,7 @@ use rust_serialization_benchmark::bench_serde_json; use rust_serialization_benchmark::bench_simd_json; #[cfg(feature = "speedy")] use rust_serialization_benchmark::bench_speedy; -#[cfg(feature = "savefile")] -use rust_serialization_benchmark::bench_savefile; -use rust_serialization_benchmark::{generate_vec}; +use rust_serialization_benchmark::generate_vec; fn bench_log(c: &mut Criterion) { use rust_serialization_benchmark::datasets::log::{Log, Logs}; @@ -194,6 +194,9 @@ fn bench_log(c: &mut Criterion) { #[cfg(feature = "ron")] bench_ron::bench(BENCH, c, &data); + #[cfg(feature = "savefile")] + bench_savefile::bench(BENCH, c, &data); + #[cfg(feature = "serde_bare")] bench_serde_bare::bench(BENCH, c, &data); @@ -208,9 +211,6 @@ fn bench_log(c: &mut Criterion) { #[cfg(feature = "speedy")] bench_speedy::bench(BENCH, c, &data); - - #[cfg(feature = "savefile")] - bench_savefile::bench(BENCH, c, &data); } fn bench_mesh(c: &mut Criterion) { @@ -338,6 +338,9 @@ fn bench_mesh(c: &mut Criterion) { #[cfg(feature = "ron")] bench_ron::bench(BENCH, c, &data); + #[cfg(feature = "savefile")] + bench_savefile::bench(BENCH, c, &data); + #[cfg(feature = "serde_bare")] bench_serde_bare::bench(BENCH, c, &data); @@ -352,9 +355,6 @@ fn bench_mesh(c: &mut Criterion) { #[cfg(feature = "speedy")] bench_speedy::bench(BENCH, c, &data); - - #[cfg(feature = "savefile")] - bench_savefile::bench(BENCH, c, &data); } fn bench_minecraft_savedata(c: &mut Criterion) { @@ -485,6 +485,9 @@ fn bench_minecraft_savedata(c: &mut Criterion) { #[cfg(feature = "ron")] bench_ron::bench(BENCH, c, &data); + #[cfg(feature = "savefile")] + bench_savefile::bench(BENCH, c, &data); + #[cfg(feature = "serde_bare")] bench_serde_bare::bench(BENCH, c, &data); @@ -499,9 +502,6 @@ fn bench_minecraft_savedata(c: &mut Criterion) { #[cfg(feature = "speedy")] bench_speedy::bench(BENCH, c, &data); - - #[cfg(feature = "savefile")] - bench_savefile::bench(BENCH, c, &data); } fn bench_mk48(c: &mut Criterion) { @@ -628,6 +628,9 @@ fn bench_mk48(c: &mut Criterion) { #[cfg(feature = "ron")] bench_ron::bench(BENCH, c, &data); + #[cfg(feature = "savefile")] + bench_savefile::bench(BENCH, c, &data); + #[cfg(feature = "serde_bare")] bench_serde_bare::bench(BENCH, c, &data); @@ -642,9 +645,6 @@ fn bench_mk48(c: &mut Criterion) { #[cfg(feature = "speedy")] bench_speedy::bench(BENCH, c, &data); - - #[cfg(feature = "savefile")] - bench_savefile::bench(BENCH, c, &data); } pub fn criterion_benchmark(c: &mut Criterion) { diff --git a/src/bench_savefile.rs b/src/bench_savefile.rs index a11f843..86e7381 100644 --- a/src/bench_savefile.rs +++ b/src/bench_savefile.rs @@ -1,10 +1,10 @@ -use std::io::Cursor; use criterion::{black_box, Criterion}; use savefile::{Deserialize, Serialize, WithSchema}; +use std::io::Cursor; pub fn bench(name: &'static str, c: &mut Criterion, data: &T) where - T: Serialize + Deserialize + WithSchema + T: Serialize + Deserialize + WithSchema, { let mut group = c.benchmark_group(format!("{}/savefile", name)); diff --git a/src/datasets/log/mod.rs b/src/datasets/log/mod.rs index fe2a881..c79b4c0 100644 --- a/src/datasets/log/mod.rs +++ b/src/datasets/log/mod.rs @@ -42,6 +42,7 @@ use crate::Generate; derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) )] #[cfg_attr(feature = "rkyv", archive_attr(derive(bytecheck::CheckBytes)))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr( feature = "simd-json", @@ -53,7 +54,6 @@ use crate::Generate; )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] -#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile), savefile_unsafe_and_fast, repr(C))] pub struct Address { pub x0: u8, pub x1: u8, diff --git a/src/datasets/mesh/mod.rs b/src/datasets/mesh/mod.rs index dd69295..b637ec1 100644 --- a/src/datasets/mesh/mod.rs +++ b/src/datasets/mesh/mod.rs @@ -52,7 +52,7 @@ use crate::Generate; )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] -#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile), savefile_unsafe_and_fast, repr(C))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Vector3 { pub x: f32, pub y: f32, @@ -141,7 +141,7 @@ impl alkahest::Pack for Vector3 { )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] -#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile), savefile_unsafe_and_fast, repr(C))] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub struct Triangle { pub v0: Vector3, pub v1: Vector3, diff --git a/src/datasets/minecraft_savedata/mod.rs b/src/datasets/minecraft_savedata/mod.rs index f770b33..8fcf77b 100644 --- a/src/datasets/minecraft_savedata/mod.rs +++ b/src/datasets/minecraft_savedata/mod.rs @@ -53,8 +53,7 @@ use crate::{generate_vec, Generate}; )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] -#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile), savefile_unsafe_and_fast)] -#[repr(u8)] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub enum GameType { Survival, Creative, diff --git a/src/datasets/mk48/mod.rs b/src/datasets/mk48/mod.rs index 8b1e708..75be3da 100644 --- a/src/datasets/mk48/mod.rs +++ b/src/datasets/mk48/mod.rs @@ -55,8 +55,7 @@ use crate::{generate_vec, Generate}; )] #[cfg_attr(feature = "speedy", derive(speedy::Readable, speedy::Writable))] #[cfg_attr(feature = "alkahest", derive(alkahest::Schema))] -#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile), savefile_unsafe_and_fast)] -#[repr(u8)] +#[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] pub enum EntityType { #[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 2.14))] ArleighBurke, diff --git a/src/lib.rs b/src/lib.rs index 62919d6..4efa1a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,8 @@ pub mod bench_rkyv; pub mod bench_rmp_serde; #[cfg(feature = "ron")] pub mod bench_ron; +#[cfg(feature = "savefile")] +pub mod bench_savefile; #[cfg(feature = "serde_bare")] pub mod bench_serde_bare; #[cfg(feature = "serde_cbor")] @@ -44,8 +46,6 @@ pub mod bench_serde_json; pub mod bench_simd_json; #[cfg(feature = "speedy")] pub mod bench_speedy; -#[cfg(feature = "savefile")] -pub mod bench_savefile; pub mod datasets; use core::{mem, ops};