mirror of
https://github.com/denoland/deno.git
synced 2025-01-11 08:33:43 -05:00
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`).
This commit is contained in:
parent
7bd2c607dd
commit
92764c0dec
4 changed files with 12 additions and 1 deletions
|
@ -287,6 +287,7 @@ pub async fn run(
|
||||||
inspect: ps.options.is_inspecting(),
|
inspect: ps.options.is_inspecting(),
|
||||||
},
|
},
|
||||||
extensions: ops::cli_exts(ps.clone()),
|
extensions: ops::cli_exts(ps.clone()),
|
||||||
|
startup_snapshot: None,
|
||||||
unsafely_ignore_certificate_errors: metadata
|
unsafely_ignore_certificate_errors: metadata
|
||||||
.unsafely_ignore_certificate_errors,
|
.unsafely_ignore_certificate_errors,
|
||||||
root_cert_store: Some(root_cert_store),
|
root_cert_store: Some(root_cert_store),
|
||||||
|
|
|
@ -430,6 +430,7 @@ pub async fn create_main_worker(
|
||||||
inspect: ps.options.is_inspecting(),
|
inspect: ps.options.is_inspecting(),
|
||||||
},
|
},
|
||||||
extensions,
|
extensions,
|
||||||
|
startup_snapshot: None,
|
||||||
unsafely_ignore_certificate_errors: ps
|
unsafely_ignore_certificate_errors: ps
|
||||||
.options
|
.options
|
||||||
.unsafely_ignore_certificate_errors()
|
.unsafely_ignore_certificate_errors()
|
||||||
|
|
|
@ -43,6 +43,7 @@ async fn main() -> Result<(), AnyError> {
|
||||||
inspect: false,
|
inspect: false,
|
||||||
},
|
},
|
||||||
extensions: vec![],
|
extensions: vec![],
|
||||||
|
startup_snapshot: None,
|
||||||
unsafely_ignore_certificate_errors: None,
|
unsafely_ignore_certificate_errors: None,
|
||||||
root_cert_store: None,
|
root_cert_store: None,
|
||||||
seed: None,
|
seed: None,
|
||||||
|
|
|
@ -27,6 +27,7 @@ use deno_core::ModuleLoader;
|
||||||
use deno_core::ModuleSpecifier;
|
use deno_core::ModuleSpecifier;
|
||||||
use deno_core::RuntimeOptions;
|
use deno_core::RuntimeOptions;
|
||||||
use deno_core::SharedArrayBufferStore;
|
use deno_core::SharedArrayBufferStore;
|
||||||
|
use deno_core::Snapshot;
|
||||||
use deno_core::SourceMapGetter;
|
use deno_core::SourceMapGetter;
|
||||||
use deno_node::RequireNpmResolver;
|
use deno_node::RequireNpmResolver;
|
||||||
use deno_tls::rustls::RootCertStore;
|
use deno_tls::rustls::RootCertStore;
|
||||||
|
@ -74,6 +75,7 @@ pub struct MainWorker {
|
||||||
pub struct WorkerOptions {
|
pub struct WorkerOptions {
|
||||||
pub bootstrap: BootstrapOptions,
|
pub bootstrap: BootstrapOptions,
|
||||||
pub extensions: Vec<Extension>,
|
pub extensions: Vec<Extension>,
|
||||||
|
pub startup_snapshot: Option<Snapshot>,
|
||||||
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
||||||
pub root_cert_store: Option<RootCertStore>,
|
pub root_cert_store: Option<RootCertStore>,
|
||||||
pub seed: Option<u64>,
|
pub seed: Option<u64>,
|
||||||
|
@ -135,6 +137,7 @@ impl Default for WorkerOptions {
|
||||||
npm_resolver: Default::default(),
|
npm_resolver: Default::default(),
|
||||||
blob_store: Default::default(),
|
blob_store: Default::default(),
|
||||||
extensions: Default::default(),
|
extensions: Default::default(),
|
||||||
|
startup_snapshot: Default::default(),
|
||||||
bootstrap: Default::default(),
|
bootstrap: Default::default(),
|
||||||
stdio: Default::default(),
|
stdio: Default::default(),
|
||||||
}
|
}
|
||||||
|
@ -242,7 +245,11 @@ impl MainWorker {
|
||||||
|
|
||||||
let mut js_runtime = JsRuntime::new(RuntimeOptions {
|
let mut js_runtime = JsRuntime::new(RuntimeOptions {
|
||||||
module_loader: Some(options.module_loader.clone()),
|
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,
|
source_map_getter: options.source_map_getter,
|
||||||
get_error_class_fn: options.get_error_class_fn,
|
get_error_class_fn: options.get_error_class_fn,
|
||||||
shared_array_buffer_store: options.shared_array_buffer_store.clone(),
|
shared_array_buffer_store: options.shared_array_buffer_store.clone(),
|
||||||
|
@ -562,6 +569,7 @@ mod tests {
|
||||||
inspect: false,
|
inspect: false,
|
||||||
},
|
},
|
||||||
extensions: vec![],
|
extensions: vec![],
|
||||||
|
startup_snapshot: None,
|
||||||
unsafely_ignore_certificate_errors: None,
|
unsafely_ignore_certificate_errors: None,
|
||||||
root_cert_store: None,
|
root_cert_store: None,
|
||||||
seed: None,
|
seed: None,
|
||||||
|
|
Loading…
Reference in a new issue