From 2502a37d41e8a7f279af74d7dacc009ee1010f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 14 Feb 2023 02:46:32 +0100 Subject: chore(build): don't compress TSC snapshot in debug build (#17772) Compressing the TSC snapshot in debug build took ~45s on M1 MacBook Pro; without compression it took ~1s. Thus we're not not using compressed snapshot, trading off a lot of build time for some startup time in debug build. --- core/snapshot_util.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'core') diff --git a/core/snapshot_util.rs b/core/snapshot_util.rs index 7e22395e0..a4bf80227 100644 --- a/core/snapshot_util.rs +++ b/core/snapshot_util.rs @@ -2,6 +2,7 @@ use std::path::Path; use std::path::PathBuf; +use std::time::Instant; use crate::Extension; use crate::InternalModuleLoaderCb; @@ -22,7 +23,8 @@ pub struct CreateSnapshotOptions { } pub fn create_snapshot(create_snapshot_options: CreateSnapshotOptions) { - let start = std::time::Instant::now(); + let mut mark = Instant::now(); + let js_runtime = JsRuntime::new(RuntimeOptions { will_snapshot: true, startup_snapshot: create_snapshot_options.startup_snapshot, @@ -35,11 +37,12 @@ pub fn create_snapshot(create_snapshot_options: CreateSnapshotOptions) { let snapshot = js_runtime.snapshot(); let snapshot_slice: &[u8] = &snapshot; println!( - "Snapshot size: {}, took {}s ({})", + "Snapshot size: {}, took {:#?} ({})", snapshot_slice.len(), - start.elapsed().as_secs_f64(), + Instant::now().saturating_duration_since(mark), create_snapshot_options.snapshot_path.display() ); + mark = Instant::now(); let maybe_compressed_snapshot: Box> = if let Some(compression_cb) = create_snapshot_options.compression_cb { @@ -54,11 +57,12 @@ pub fn create_snapshot(create_snapshot_options: CreateSnapshotOptions) { (compression_cb)(&mut vec, snapshot_slice); println!( - "Snapshot compressed size: {}, took {}s ({})", + "Snapshot compressed size: {}, took {:#?} ({})", vec.len(), - start.elapsed().as_secs_f64(), + Instant::now().saturating_duration_since(mark), create_snapshot_options.snapshot_path.display() ); + mark = std::time::Instant::now(); Box::new(vec) } else { @@ -71,9 +75,9 @@ pub fn create_snapshot(create_snapshot_options: CreateSnapshotOptions) { ) .unwrap(); println!( - "Snapshot written to: {}, took: {}s", + "Snapshot written, took: {:#?} ({})", + Instant::now().saturating_duration_since(mark), create_snapshot_options.snapshot_path.display(), - start.elapsed().as_secs_f64() ); } -- cgit v1.2.3