summaryrefslogtreecommitdiff
path: root/cli/worker.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/worker.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/worker.rs')
-rw-r--r--cli/worker.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/cli/worker.rs b/cli/worker.rs
index 24397b6bf..3b09714d5 100644
--- a/cli/worker.rs
+++ b/cli/worker.rs
@@ -83,6 +83,15 @@ pub trait HmrRunner: Send + Sync {
async fn run(&mut self) -> Result<(), AnyError>;
}
+pub trait CliCodeCache: code_cache::CodeCache {
+ /// Gets if the code cache is still enabled.
+ fn enabled(&self) -> bool {
+ true
+ }
+
+ fn as_code_cache(self: Arc<Self>) -> Arc<dyn code_cache::CodeCache>;
+}
+
#[async_trait::async_trait(?Send)]
pub trait CoverageCollector: Send + Sync {
async fn start_collecting(&mut self) -> Result<(), AnyError>;
@@ -127,7 +136,7 @@ pub struct CliMainWorkerOptions {
struct SharedWorkerState {
blob_store: Arc<BlobStore>,
broadcast_channel: InMemoryBroadcastChannel,
- code_cache: Option<Arc<dyn code_cache::CodeCache>>,
+ code_cache: Option<Arc<dyn CliCodeCache>>,
compiled_wasm_module_store: CompiledWasmModuleStore,
feature_checker: Arc<FeatureChecker>,
fs: Arc<dyn deno_fs::FileSystem>,
@@ -393,7 +402,7 @@ impl CliMainWorkerFactory {
#[allow(clippy::too_many_arguments)]
pub fn new(
blob_store: Arc<BlobStore>,
- code_cache: Option<Arc<dyn code_cache::CodeCache>>,
+ code_cache: Option<Arc<dyn CliCodeCache>>,
feature_checker: Arc<FeatureChecker>,
fs: Arc<dyn deno_fs::FileSystem>,
maybe_file_watcher_communicator: Option<Arc<WatcherCommunicator>>,
@@ -554,7 +563,7 @@ impl CliMainWorkerFactory {
),
feature_checker,
permissions,
- v8_code_cache: shared.code_cache.clone(),
+ v8_code_cache: shared.code_cache.clone().map(|c| c.as_code_cache()),
};
let options = WorkerOptions {