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 /cli/build.rs | |
parent | a3b3a792b5c8dd2fa3e1b29f7fe5a7f3423f25c0 (diff) |
feat(cli, runtime): compress snapshots (#13320)
Diffstat (limited to 'cli/build.rs')
-rw-r--r-- | cli/build.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/cli/build.rs b/cli/build.rs index 48c55e628..87c688480 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -38,7 +38,30 @@ fn create_snapshot( 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(), + ); + + vec.extend_from_slice( + &zstd::block::compress(snapshot_slice, 22) + .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()); } |