diff --git a/garden-sea/src/node.rs b/garden-sea/src/node.rs index 4b85d1a34e..4383aebe62 100644 --- a/garden-sea/src/node.rs +++ b/garden-sea/src/node.rs @@ -39,6 +39,18 @@ where #[cfg(all(target_os = "linux"))] command.env("GARDEN_SEA_TARGET_ENV", TARGET_ENV); + // Enable v8 compilation cache by default. That saves ~10-30ms on an M2 mac and we've seen 2 seconds startup time shaved off on Windows. + // See also https://nodejs.org/api/cli.html#node_compile_cachedir + let enable_compile_cache = env::var("GARDEN_COMPILE_CACHE").unwrap_or("true".into()); + if enable_compile_cache == "true" || enable_compile_cache == "1" { + let cache_dir = path.join("v8cache"); + fs::create_dir_all(cache_dir.clone())?; + command.env( + "NODE_COMPILE_CACHE", + OsString::from(cache_dir), + ); + } + // Allow users to override the heap size if needed. let max_old_space_size = env::var("GARDEN_MAX_OLD_SPACE_SIZE").unwrap_or("4096".into()); let max_semi_space_size = env::var("GARDEN_MAX_SEMI_SPACE_SIZE").unwrap_or("64".into());