summaryrefslogtreecommitdiff
path: root/runtime/build.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-03-21 16:33:12 -0600
committerGitHub <noreply@github.com>2023-03-21 22:33:12 +0000
commit0b4770fa7daf274ab01923fb09fd604aeb27e417 (patch)
treebee10a226239c2787caa87944a5f80783048d9f9 /runtime/build.rs
parent253b556e6f430012c3094d47838fe397fa588028 (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 'runtime/build.rs')
-rw-r--r--runtime/build.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/runtime/build.rs b/runtime/build.rs
index 016ece810..ec7c9642c 100644
--- a/runtime/build.rs
+++ b/runtime/build.rs
@@ -17,11 +17,12 @@ mod startup_snapshot {
use deno_core::snapshot_util::*;
use deno_core::Extension;
use deno_core::ExtensionFileSource;
+ use deno_core::ModuleCode;
use std::path::Path;
fn transpile_ts_for_snapshotting(
file_source: &ExtensionFileSource,
- ) -> Result<String, AnyError> {
+ ) -> Result<ModuleCode, AnyError> {
let media_type = MediaType::from_path(Path::new(&file_source.specifier));
let should_transpile = match media_type {
@@ -41,7 +42,7 @@ mod startup_snapshot {
let parsed = deno_ast::parse_module(ParseParams {
specifier: file_source.specifier.to_string(),
- text_info: SourceTextInfo::from_string(code),
+ text_info: SourceTextInfo::from_string(code.take_as_string()),
media_type,
capture_tokens: false,
scope_analysis: false,
@@ -53,7 +54,7 @@ mod startup_snapshot {
..Default::default()
})?;
- Ok(transpiled_source.text)
+ Ok(transpiled_source.text.into())
}
#[derive(Clone)]