Skip to content

Commit

Permalink
improvement: improve cli startup performance using v8 cache (#6049)
Browse files Browse the repository at this point in the history
* feat: experimental flag to enable v8 cache

This can speed up the core command startup time.

Can be enabled by now using `GARDEN_COMPILE_CACHE=1` and is disabled by
default.

On my M2 mac it saves ~11-30ms when running `garden --help`

* improvement: enable v8 cache by default
  • Loading branch information
stefreak committed May 15, 2024
1 parent 451c484 commit 7d8034b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions garden-sea/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 7d8034b

Please sign in to comment.