Skip to content

Commit

Permalink
compress embedded corpus
Browse files Browse the repository at this point in the history
~25% reduction in binary size
  • Loading branch information
evanrichter committed Jul 3, 2023
1 parent 18ae02a commit 7030c06
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ anyhow = "1.0.71"
clap = "4.3.3"
glob = "0.3.1"
log = "0.4.19"
lz4_flex = { version = "0.11.1", default-features = false }
postcard = { version = "1.0.4", features = ["use-std"], default-features = false }
serde = { version = "1.0.164", features = ["derive"] }
simple_logger = "4.1.0"
Expand All @@ -23,5 +24,6 @@ rand = "0.8.5"
anyhow = "1.0.71"
glob = "0.3.1"
log = "0.4.19"
lz4_flex = { version = "0.11.1", default-features = false }
postcard = { version = "1.0.4", features = ["use-std"], default-features = false }
serde = { version = "1.0.164", features = ["derive"] }
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ fn main() {
// serialize to bytes
let bytes = postcard::to_stdvec(&default).unwrap();

// compress
let bytes = lz4_flex::compress(&bytes);

// output path to target build folder
let mut outfile = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
outfile.push("default.pc");
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,11 @@ fn main() -> Result<()> {
// serialized bytes embedded from build.rs
let bytes = include_bytes!(concat!(env!("OUT_DIR"), "/default.pc"));

// decompress
let bytes = lz4_flex::decompress(bytes, 39364573).unwrap();

// deserialize
postcard::from_bytes(bytes).unwrap()
postcard::from_bytes(&bytes).unwrap()
};

let corpus_stats = match args.get_one::<&str>("corpus") {
Expand Down

0 comments on commit 7030c06

Please sign in to comment.