diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/Cargo.toml | 2 | ||||
-rw-r--r-- | cli/build.rs | 25 | ||||
-rw-r--r-- | cli/tsc.rs | 20 |
3 files changed, 43 insertions, 4 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 15a82b5eb..7fd34e2f1 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -33,6 +33,7 @@ deno_websocket = { version = "0.36.0", path = "../ext/websocket" } deno_webstorage = { version = "0.26.0", path = "../ext/webstorage" } regex = "=1.5.4" serde = { version = "=1.0.133", features = ["derive"] } +zstd = '=0.9.2' [target.'cfg(windows)'.build-dependencies] winapi = "=0.3.9" @@ -85,6 +86,7 @@ text_lines = "=0.4.1" tokio = { version = "=1.14", features = ["full"] } uuid = { version = "=0.8.2", features = ["v4", "serde"] } walkdir = "=2.3.2" +zstd = '=0.9.2' [target.'cfg(windows)'.dependencies] fwdansi = "=1.1.0" 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()); } diff --git a/cli/tsc.rs b/cli/tsc.rs index 3dfb97588..a2265e36f 100644 --- a/cli/tsc.rs +++ b/cli/tsc.rs @@ -51,11 +51,25 @@ pub static SHARED_GLOBALS_LIB: &str = pub static WINDOW_LIB: &str = include_str!("dts/lib.deno.window.d.ts"); pub static UNSTABLE_NS_LIB: &str = include_str!("dts/lib.deno.unstable.d.ts"); -pub static COMPILER_SNAPSHOT: &[u8] = - include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.bin")); +pub static COMPILER_SNAPSHOT: Lazy<Box<[u8]>> = Lazy::new( + #[cold] + #[inline(never)] + || { + static COMPRESSED_COMPILER_SNAPSHOT: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.bin")); + + zstd::block::decompress( + &COMPRESSED_COMPILER_SNAPSHOT[4..], + u32::from_le_bytes(COMPRESSED_COMPILER_SNAPSHOT[0..4].try_into().unwrap()) + as usize, + ) + .unwrap() + .into_boxed_slice() + }, +); pub fn compiler_snapshot() -> Snapshot { - Snapshot::Static(COMPILER_SNAPSHOT) + Snapshot::Static(&*COMPILER_SNAPSHOT) } macro_rules! inc { |