diff options
author | Mathias Lafeldt <mathias.lafeldt@gmail.com> | 2022-11-10 12:46:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 12:46:26 +0100 |
commit | 92764c0decb370b0f8a78770314ceda7228d315f (patch) | |
tree | f04ff23a216540f59364a698ba1a600d1b87b7dc /runtime/worker.rs | |
parent | 7bd2c607dd5aba82f4afb94a5c2e35ba5f0738cf (diff) |
feat(runtime): support creating workers with custom v8 snapshots (#16553)
This PR makes it possible for applications to create workers from custom
snapshots to improve runtime performance (without having to fork/copy
`runtime/workers.rs`).
Diffstat (limited to 'runtime/worker.rs')
-rw-r--r-- | runtime/worker.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/runtime/worker.rs b/runtime/worker.rs index de15c9f6f..dcc2727db 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -27,6 +27,7 @@ use deno_core::ModuleLoader; use deno_core::ModuleSpecifier; use deno_core::RuntimeOptions; use deno_core::SharedArrayBufferStore; +use deno_core::Snapshot; use deno_core::SourceMapGetter; use deno_node::RequireNpmResolver; use deno_tls::rustls::RootCertStore; @@ -74,6 +75,7 @@ pub struct MainWorker { pub struct WorkerOptions { pub bootstrap: BootstrapOptions, pub extensions: Vec<Extension>, + pub startup_snapshot: Option<Snapshot>, pub unsafely_ignore_certificate_errors: Option<Vec<String>>, pub root_cert_store: Option<RootCertStore>, pub seed: Option<u64>, @@ -135,6 +137,7 @@ impl Default for WorkerOptions { npm_resolver: Default::default(), blob_store: Default::default(), extensions: Default::default(), + startup_snapshot: Default::default(), bootstrap: Default::default(), stdio: Default::default(), } @@ -242,7 +245,11 @@ impl MainWorker { let mut js_runtime = JsRuntime::new(RuntimeOptions { module_loader: Some(options.module_loader.clone()), - startup_snapshot: Some(js::deno_isolate_init()), + startup_snapshot: Some( + options + .startup_snapshot + .unwrap_or_else(js::deno_isolate_init), + ), source_map_getter: options.source_map_getter, get_error_class_fn: options.get_error_class_fn, shared_array_buffer_store: options.shared_array_buffer_store.clone(), @@ -562,6 +569,7 @@ mod tests { inspect: false, }, extensions: vec![], + startup_snapshot: None, unsafely_ignore_certificate_errors: None, root_cert_store: None, seed: None, |