diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-03-21 16:33:12 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-21 22:33:12 +0000 |
commit | 0b4770fa7daf274ab01923fb09fd604aeb27e417 (patch) | |
tree | bee10a226239c2787caa87944a5f80783048d9f9 /cli/emit.rs | |
parent | 253b556e6f430012c3094d47838fe397fa588028 (diff) |
perf(core) Reduce script name and script code copies (#18298)
Reduce the number of copies and allocations of script code by carrying
around ownership/reference information from creation time.
As an advantage, this allows us to maintain the identity of `&'static
str`-based scripts and use v8's external 1-byte strings (to avoid
incorrectly passing non-ASCII strings, debug `assert!`s gate all string
reference paths).
Benchmark results:
Perf improvements -- ~0.1 - 0.2ms faster, but should reduce garbage
w/external strings and reduces data copies overall. May also unlock some
more interesting optimizations in the future.
This requires adding some generics to functions, but manual
monomorphization has been applied (outer/inner function) to avoid code
bloat.
Diffstat (limited to 'cli/emit.rs')
-rw-r--r-- | cli/emit.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/cli/emit.rs b/cli/emit.rs index d322fe38e..f69f70cc7 100644 --- a/cli/emit.rs +++ b/cli/emit.rs @@ -5,6 +5,7 @@ use crate::cache::FastInsecureHasher; use crate::cache::ParsedSourceCache; use deno_core::error::AnyError; +use deno_core::ModuleCode; use deno_core::ModuleSpecifier; use deno_graph::MediaType; use std::sync::Arc; @@ -27,11 +28,11 @@ pub fn emit_parsed_source( source: &Arc<str>, emit_options: &deno_ast::EmitOptions, emit_config_hash: u64, -) -> Result<String, AnyError> { +) -> Result<ModuleCode, AnyError> { let source_hash = get_source_hash(source, emit_config_hash); if let Some(emit_code) = emit_cache.get_emit_code(specifier, source_hash) { - Ok(emit_code) + Ok(emit_code.into()) } else { // this will use a cached version if it exists let parsed_source = parsed_source_cache.get_or_parse_module( @@ -42,6 +43,6 @@ pub fn emit_parsed_source( let transpiled_source = parsed_source.transpile(emit_options)?; debug_assert!(transpiled_source.source_map.is_none()); emit_cache.set_emit_code(specifier, source_hash, &transpiled_source.text); - Ok(transpiled_source.text) + Ok(transpiled_source.text.into()) } } |