diff options
author | evan <github@evan.lol> | 2022-01-10 18:51:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-10 15:51:23 -0800 |
commit | b66afa2518042cda239ef07f221722781ca660f6 (patch) | |
tree | 629ebc8c74496df7bf1588e2e4f5ec06fcb4e788 /runtime/build.rs | |
parent | a3b3a792b5c8dd2fa3e1b29f7fe5a7f3423f25c0 (diff) |
feat(cli, runtime): compress snapshots (#13320)
Diffstat (limited to 'runtime/build.rs')
-rw-r--r-- | runtime/build.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/runtime/build.rs b/runtime/build.rs index d1e8517b8..e2fe21b9e 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -37,7 +37,32 @@ mod not_docs { let snapshot = js_runtime.snapshot(); let snapshot_slice: &[u8] = &*snapshot; println!("Snapshot size: {}", snapshot_slice.len()); - std::fs::write(&snapshot_path, snapshot_slice).unwrap(); + + let compressed_snapshot_with_size = { + let mut vec = vec![]; + + vec.extend_from_slice( + &u32::try_from(snapshot.len()) + .expect("snapshot larger than 4gb") + .to_le_bytes(), + ); + + lzzzz::lz4_hc::compress_to_vec( + snapshot_slice, + &mut vec, + lzzzz::lz4_hc::CLEVEL_MAX, + ) + .expect("snapshot compression failed"); + + vec + }; + + println!( + "Snapshot compressed size: {}", + compressed_snapshot_with_size.len() + ); + + std::fs::write(&snapshot_path, compressed_snapshot_with_size).unwrap(); println!("Snapshot written to: {} ", snapshot_path.display()); } |