From f2129e4f94d771c5c996210df6c1b4a25cffed6c Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 3 Jul 2025 12:59:29 -0400 Subject: [PATCH] perf: bust emit cache only on deno_ast version change (#29984) The emit cache is pretty stable nowadays, so we could probably just cache bust whenever the deno_ast version changes instead of the CLI version. This will also allow stuff like deno-js-loader to reuse cached emits. --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- cli/factory.rs | 3 --- cli/lsp/config.rs | 4 ---- libs/resolver/cache/emit.rs | 11 ++++------- libs/resolver/factory.rs | 8 ++++---- 6 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index af8f74524e..824d2c12cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1636,9 +1636,9 @@ dependencies = [ [[package]] name = "deno_ast" -version = "0.48.0" +version = "0.48.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f883bd8eae4dfc8019d925ec3dd04b634b6af9346a5168acc259d55f5f5021d" +checksum = "0ced09fdb8884e29716cc0691e8510f9c655762bbb9da3111dacc0a2ef6e8960" dependencies = [ "base64 0.22.1", "capacity_builder", diff --git a/Cargo.toml b/Cargo.toml index 63826e2b91..be34aa5076 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,7 +58,7 @@ license = "MIT" repository = "https://github.com/denoland/deno" [workspace.dependencies] -deno_ast = { version = "=0.48.0", features = ["transpiling"] } +deno_ast = { version = "=0.48.1", features = ["transpiling"] } deno_core = { version = "0.352.0" } deno_cache_dir = "=0.23.0" diff --git a/cli/factory.rs b/cli/factory.rs index e7fb7dd953..ddfdd72e63 100644 --- a/cli/factory.rs +++ b/cli/factory.rs @@ -1220,9 +1220,6 @@ fn new_workspace_factory_options( } ConfigFlag::Disabled => ConfigDiscoveryOption::Disabled, }, - emit_cache_version: Cow::Borrowed( - deno_lib::version::DENO_VERSION_INFO.deno, - ), maybe_custom_deno_dir_root: flags.internal.cache_path.clone(), // For `deno install/add/remove/init` we want to force the managed // resolver so it can set up the `node_modules/` directory. diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index ca7b3a54bb..acde81130e 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -1,6 +1,5 @@ // Copyright 2018-2025 the Deno authors. MIT license. -use std::borrow::Cow; use std::collections::BTreeMap; use std::collections::BTreeSet; use std::collections::HashMap; @@ -1478,9 +1477,6 @@ impl ConfigData { config_discovery: ConfigDiscoveryOption::DiscoverCwd, maybe_custom_deno_dir_root: None, is_package_manager_subcommand: false, - emit_cache_version: Cow::Borrowed( - deno_lib::version::DENO_VERSION_INFO.deno, - ), frozen_lockfile: None, lock_arg: None, lockfile_skip_write: false, diff --git a/libs/resolver/cache/emit.rs b/libs/resolver/cache/emit.rs index 2ed3241f28..e1e618f8b7 100644 --- a/libs/resolver/cache/emit.rs +++ b/libs/resolver/cache/emit.rs @@ -40,13 +40,10 @@ impl EmitCache { disk_cache: DiskCache, cache_version: Cow<'static, str>, ) -> Self { - let mode = match sys - .env_var("DENO_EMIT_CACHE_MODE") - .unwrap_or_default() - .as_str() - { - "normal" | "" => Mode::Normal, - "disable" => Mode::Disable, + let emit_cache_mode = sys.env_var_os("DENO_EMIT_CACHE_MODE"); + let mode = match emit_cache_mode.as_ref().and_then(|s| s.to_str()) { + Some("normal") | Some("") | None => Mode::Normal, + Some("disable") => Mode::Disable, _ => { log::warn!("Unknown DENO_EMIT_CACHE_MODE value, defaulting to normal"); Mode::Normal diff --git a/libs/resolver/factory.rs b/libs/resolver/factory.rs index f7a69657aa..190a6e4809 100644 --- a/libs/resolver/factory.rs +++ b/libs/resolver/factory.rs @@ -198,9 +198,6 @@ pub struct WorkspaceFactoryOptions { pub additional_config_file_names: &'static [&'static str], pub config_discovery: ConfigDiscoveryOption, pub is_package_manager_subcommand: bool, - /// Version to use for the emit cache. This is something that - /// should change when the version of the underlying emit changes. - pub emit_cache_version: Cow<'static, str>, pub frozen_lockfile: Option, pub lock_arg: Option, /// Whether to skip writing to the lockfile. @@ -301,7 +298,10 @@ impl WorkspaceFactory { Ok(new_rc(EmitCache::new( &self.sys, self.deno_dir()?.gen_cache.clone(), - self.options.emit_cache_version.clone(), + #[cfg(feature = "deno_ast")] + Cow::Borrowed(deno_ast::VERSION), + #[cfg(not(feature = "deno_ast"))] + Cow::Borrowed(env!("CARGO_PKG_VERSION")), ))) }) }