diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-03-17 16:15:27 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-17 22:15:27 +0000 |
commit | 3487fde236d0852a8b0672c293fa41a741f471e8 (patch) | |
tree | af466368147a08b787080446319a3a46a60ee37d /cli | |
parent | e55b448730160a6e4df9815a268d4049ac89deab (diff) |
perf(core) Reduce copying and cloning in extension initialization (#18252)
Follow-up to #18210:
* we are passing the generated `cfg` object into the state function
rather than passing individual config fields
* reduce cloning dramatically by making the state_fn `FnOnce`
* `take` for `ExtensionBuilder` to avoid more unnecessary copies
* renamed `config` to `options`
Diffstat (limited to 'cli')
-rw-r--r-- | cli/build.rs | 14 | ||||
-rw-r--r-- | cli/lsp/tsc.rs | 6 | ||||
-rw-r--r-- | cli/ops/bench.rs | 8 | ||||
-rw-r--r-- | cli/ops/mod.rs | 6 | ||||
-rw-r--r-- | cli/ops/testing.rs | 10 | ||||
-rw-r--r-- | cli/tsc/mod.rs | 21 |
6 files changed, 31 insertions, 34 deletions
diff --git a/cli/build.rs b/cli/build.rs index e4df856f7..9068723d4 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -1,9 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -use std::cell::RefCell; use std::env; use std::path::PathBuf; -use std::rc::Rc; use deno_core::snapshot_util::*; use deno_core::Extension; @@ -122,15 +120,15 @@ mod ts { "00_typescript.js", "99_main_compiler.js", ], - config = { + options = { op_crate_libs: HashMap<&'static str, PathBuf>, build_libs: Vec<&'static str>, path_dts: PathBuf, }, - state = |state, op_crate_libs, build_libs, path_dts| { - state.put(op_crate_libs); - state.put(build_libs); - state.put(path_dts); + state = |state, options| { + state.put(options.op_crate_libs); + state.put(options.build_libs); + state.put(options.path_dts); }, ); @@ -362,7 +360,7 @@ fn create_cli_snapshot(snapshot_path: PathBuf) { deno_tls::deno_tls::init_ops(), deno_napi::deno_napi::init_ops::<PermissionsContainer>(), deno_http::deno_http::init_ops(), - deno_io::deno_io::init_ops(Rc::new(RefCell::new(Some(Default::default())))), + deno_io::deno_io::init_ops(Default::default()), deno_fs::deno_fs::init_ops::<PermissionsContainer>(false), deno_flash::deno_flash::init_ops::<PermissionsContainer>(false), // No --unstable deno_node::deno_node_loading::init_ops::<PermissionsContainer>(None), // No --unstable. diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 910d13691..91eb6e24b 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -2834,13 +2834,13 @@ deno_core::extension!(deno_tsc, op_script_names, op_script_version, ], - config = { + options = { performance: Arc<Performance> }, - state = |state, performance| { + state = |state, options| { state.put(State::new( Arc::new(StateSnapshot::default()), - performance, + options.performance, )); }, ); diff --git a/cli/ops/bench.rs b/cli/ops/bench.rs index 7bd3f988a..6fa9edee8 100644 --- a/cli/ops/bench.rs +++ b/cli/ops/bench.rs @@ -30,13 +30,13 @@ deno_core::extension!(deno_bench, op_dispatch_bench_event, op_bench_now, ], - config = { + options = { sender: UnboundedSender<BenchEvent>, filter: TestFilter, }, - state = |state, sender, filter| { - state.put(sender); - state.put(filter); + state = |state, options| { + state.put(options.sender); + state.put(options.filter); }, ); diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs index 562aa8649..c12409514 100644 --- a/cli/ops/mod.rs +++ b/cli/ops/mod.rs @@ -15,11 +15,11 @@ pub fn cli_exts(ps: ProcState) -> Vec<Extension> { deno_core::extension!(deno_cli, ops = [op_npm_process_state], - config = { + options = { ps: ProcState, }, - state = |state, ps| { - state.put(ps); + state = |state, options| { + state.put(options.ps); }, ); diff --git a/cli/ops/testing.rs b/cli/ops/testing.rs index f32e96147..0849f1c7a 100644 --- a/cli/ops/testing.rs +++ b/cli/ops/testing.rs @@ -34,15 +34,15 @@ deno_core::extension!(deno_test, op_dispatch_test_event, op_tests_should_stop, ], - config = { + options = { sender: TestEventSender, fail_fast_tracker: FailFastTracker, filter: TestFilter, }, - state = |state, sender, fail_fast_tracker, filter| { - state.put(sender); - state.put(fail_fast_tracker); - state.put(filter); + state = |state, options| { + state.put(options.sender); + state.put(options.fail_fast_tracker); + state.put(options.filter); }, ); diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index 387fd3aa1..45589780f 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -41,7 +41,6 @@ use std::collections::HashMap; use std::fmt; use std::path::Path; use std::path::PathBuf; -use std::rc::Rc; use std::sync::Arc; mod diagnostics; @@ -829,19 +828,19 @@ pub fn exec(request: Request) -> Result<Response, AnyError> { deno_core::extension!(deno_cli_tsc, ops_fn = deno_ops, - config = { - request: Rc<Request>, + options = { + request: Request, root_map: HashMap<String, Url>, remapped_specifiers: HashMap<String, Url>, }, - state = |state, request, root_map, remapped_specifiers| { + state = |state, options| { state.put(State::new( - request.graph.clone(), - request.hash_data.clone(), - request.maybe_npm_resolver.clone(), - request.maybe_tsbuildinfo.clone(), - root_map, - remapped_specifiers, + options.request.graph, + options.request.hash_data, + options.request.maybe_npm_resolver, + options.request.maybe_tsbuildinfo, + options.root_map, + options.remapped_specifiers, std::env::current_dir() .context("Unable to get CWD") .unwrap(), @@ -861,7 +860,7 @@ pub fn exec(request: Request) -> Result<Response, AnyError> { let mut runtime = JsRuntime::new(RuntimeOptions { startup_snapshot: Some(compiler_snapshot()), extensions: vec![deno_cli_tsc::init_ops( - Rc::new(request), + request, root_map, remapped_specifiers, )], |