GithubHelp home page GithubHelp logo

Comments (5)

RobDavenport avatar RobDavenport commented on September 10, 2024

Recent benchmarks:

https://david.kolo.ski/rust_serialization_benchmark/

https://www.reddit.com/r/rust/comments/13hwwhj/bitcode_04_release_binary_serialization_format/

This seems like it would be worth it now.

from gamercade_console.

RobDavenport avatar RobDavenport commented on September 10, 2024

Interestingly I ran a test with this on the 3d example and somehow came up with a bigger file:

  1. bincode + zstd: 143kb
  2. bitcode raw: 443kb
  3. bitcode + zstd: 168kb

from gamercade_console.

RobDavenport avatar RobDavenport commented on September 10, 2024

Closing this for now, seems unnecessary to continue exploring this at this point

from gamercade_console.

caibear avatar caibear commented on September 10, 2024

bitcode author here, your test on Feb 4 was with an old version of bitcode (presumably 0.4 or 0.5). These old versions didn't compress very well because they serialized bits while compression like zstd operates on bytes. Luckily I have released a new version bitcode = "0.6" which compresses much better.

Using version 3de7156db381dd2fa1943d59551360819e3e27f7 because the latest version failed to deserialize, I ran some tests on example_3d.gcrom. I initially measured a small regression from bincode 160kb -> 164kb. However, after further investigation I managed to get an improvement to 115kb with a small code change.

I replaced

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
impl<'de> Deserialize<'de> for Color {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let hex = if deserializer.is_human_readable() {
let hex: String = Deserialize::deserialize(deserializer)?;
u32::from_str_radix(&hex, 16).map_err(serde::de::Error::custom)?
} else {
Deserialize::deserialize(deserializer)?
};
Ok(Color::from_hex(hex))
}
}
impl Serialize for Color {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
if serializer.is_human_readable() {
serializer.serialize_str(&format!("{:x}", self.to_hex()))
} else {
serializer.serialize_u32(self.to_hex())
}
}
}

with #[derive(Serialize, Deserialize)] which serializes the color as (u8, u8, u8, u8) instead of u32. This allows bitcode to leverage its improved compression (but has no effect on bincode). Assuming you want to keep the human readable representation, I recommend using (self.r, self.g, self.b, self.a).serialize(serializer) to achieve the same effect.

from gamercade_console.

RobDavenport avatar RobDavenport commented on September 10, 2024

Thanks for looking into this. Going to re-open the issue as it will be worth it to look into it again in the future!

from gamercade_console.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.