summaryrefslogtreecommitdiff
path: root/cli/standalone/binary.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-11-18 15:09:28 -0500
committerGitHub <noreply@github.com>2024-11-18 20:09:28 +0000
commitdd4570ed85888d9659a2eec98437dbd6de4a5799 (patch)
tree0880f06e3b0f51267ad6e1619941dcc07c5c14c6 /cli/standalone/binary.rs
parent3ba464dbc40dd2d6bd3f7a1912aa8f0fad95058f (diff)
perf(compile): code cache (#26528)
Adds a lazily created code cache to `deno compile` by default. The code cache is created on first run to a single file in the temp directory and is only written once. After it's been written, the code cache becomes read only on subsequent runs. Only the modules loaded during startup are cached (dynamic imports are not code cached). The code cache can be disabled by compiling with `--no-code-cache`.
Diffstat (limited to 'cli/standalone/binary.rs')
-rw-r--r--cli/standalone/binary.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/cli/standalone/binary.rs b/cli/standalone/binary.rs
index 3efd8ee14..37753bafc 100644
--- a/cli/standalone/binary.rs
+++ b/cli/standalone/binary.rs
@@ -64,6 +64,7 @@ use crate::args::NpmInstallDepsProvider;
use crate::args::PermissionFlags;
use crate::args::UnstableConfig;
use crate::cache::DenoDir;
+use crate::cache::FastInsecureHasher;
use crate::emit::Emitter;
use crate::file_fetcher::FileFetcher;
use crate::http_util::HttpClientProvider;
@@ -174,6 +175,7 @@ pub struct SerializedWorkspaceResolver {
pub struct Metadata {
pub argv: Vec<String>,
pub seed: Option<u64>,
+ pub code_cache_key: Option<u64>,
pub permissions: PermissionFlags,
pub location: Option<Url>,
pub v8_flags: Vec<String>,
@@ -604,10 +606,21 @@ impl<'a> DenoCompileBinaryWriter<'a> {
VfsBuilder::new(root_path.clone())?
};
let mut remote_modules_store = RemoteModulesStoreBuilder::default();
+ let mut code_cache_key_hasher = if cli_options.code_cache_enabled() {
+ Some(FastInsecureHasher::new_deno_versioned())
+ } else {
+ None
+ };
for module in graph.modules() {
if module.specifier().scheme() == "data" {
continue; // don't store data urls as an entry as they're in the code
}
+ if let Some(hasher) = &mut code_cache_key_hasher {
+ if let Some(source) = module.source() {
+ hasher.write(module.specifier().as_str().as_bytes());
+ hasher.write(source.as_bytes());
+ }
+ }
let (maybe_source, media_type) = match module {
deno_graph::Module::Js(m) => {
let source = if m.media_type.is_emittable() {
@@ -675,6 +688,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
let metadata = Metadata {
argv: compile_flags.args.clone(),
seed: cli_options.seed(),
+ code_cache_key: code_cache_key_hasher.map(|h| h.finish()),
location: cli_options.location_flag().clone(),
permissions: cli_options.permission_flags().clone(),
v8_flags: cli_options.v8_flags().clone(),