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`.
This commit is contained in:
David Sherret 2024-11-18 15:09:28 -05:00 committed by GitHub
parent 3ba464dbc4
commit dd4570ed85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 703 additions and 20 deletions

View file

@ -2,20 +2,12 @@
use deno_core::ModuleSpecifier;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CodeCacheType {
EsModule,
Script,
}
impl CodeCacheType {
pub fn as_str(&self) -> &str {
match self {
Self::EsModule => "esmodule",
Self::Script => "script",
}
}
}
pub trait CodeCache: Send + Sync {
fn get_sync(
&self,
@ -23,6 +15,7 @@ pub trait CodeCache: Send + Sync {
code_cache_type: CodeCacheType,
source_hash: u64,
) -> Option<Vec<u8>>;
fn set_sync(
&self,
specifier: ModuleSpecifier,