1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

Revert "perf(core): use static specifier in ExtensionFileSource (#182… (#18270)

…64)"

This reverts commit 8af0c83519.

Causes bench stage to fail on CI.
This commit is contained in:
Bartek Iwańczuk 2023-03-18 15:25:28 -04:00 committed by GitHub
parent 00f4c0df97
commit f6c364fcf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 43 additions and 46 deletions

View file

@ -12,7 +12,7 @@ use deno_core::ExtensionFileSourceCode;
fn setup() -> Vec<Extension> { fn setup() -> Vec<Extension> {
vec![Extension::builder("bench_setup") vec![Extension::builder("bench_setup")
.js(vec![ExtensionFileSource { .js(vec![ExtensionFileSource {
specifier: "ext:bench_setup/setup.js", specifier: "setup.js".to_string(),
code: ExtensionFileSourceCode::IncludedInBinary( code: ExtensionFileSourceCode::IncludedInBinary(
r#" r#"
const hello = "hello world\n"; const hello = "hello world\n";

View file

@ -320,7 +320,7 @@ deno_core::extension!(
], ],
customizer = |ext: &mut ExtensionBuilder| { customizer = |ext: &mut ExtensionBuilder| {
ext.esm(vec![ExtensionFileSource { ext.esm(vec![ExtensionFileSource {
specifier: "ext:cli/runtime/js/99_main.js", specifier: "runtime/js/99_main.js".to_string(),
code: ExtensionFileSourceCode::LoadedFromFsDuringSnapshot( code: ExtensionFileSourceCode::LoadedFromFsDuringSnapshot(
std::path::PathBuf::from(deno_runtime::js::PATH_FOR_99_MAIN_JS), std::path::PathBuf::from(deno_runtime::js::PATH_FOR_99_MAIN_JS),
), ),

View file

@ -37,7 +37,7 @@ impl ExtensionFileSourceCode {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct ExtensionFileSource { pub struct ExtensionFileSource {
pub specifier: &'static str, pub specifier: String,
pub code: ExtensionFileSourceCode, pub code: ExtensionFileSourceCode,
} }
pub type OpFnRef = v8::FunctionCallback; pub type OpFnRef = v8::FunctionCallback;
@ -189,11 +189,11 @@ macro_rules! extension {
#[allow(unused_variables)] #[allow(unused_variables)]
fn with_js(ext: &mut $crate::ExtensionBuilder) { fn with_js(ext: &mut $crate::ExtensionBuilder) {
$( ext.esm( $( ext.esm(
$crate::include_js_files!( $name $( dir $dir_esm , )? $( $esm , )* ) $crate::include_js_files!( $( dir $dir_esm , )? $( $esm , )* )
); )? ); )?
$( $(
ext.esm(vec![ExtensionFileSource { ext.esm(vec![ExtensionFileSource {
specifier: "ext:setup", specifier: "ext:setup".to_string(),
code: ExtensionFileSourceCode::IncludedInBinary($esm_setup_script), code: ExtensionFileSourceCode::IncludedInBinary($esm_setup_script),
}]); }]);
)? )?
@ -201,7 +201,7 @@ macro_rules! extension {
ext.esm_entry_point($esm_entry_point); ext.esm_entry_point($esm_entry_point);
)? )?
$( ext.js( $( ext.js(
$crate::include_js_files!( $name $( dir $dir_js , )? $( $js , )* ) $crate::include_js_files!( $( dir $dir_js , )? $( $js , )* )
); )? ); )?
} }
@ -451,11 +451,28 @@ pub struct ExtensionBuilder {
impl ExtensionBuilder { impl ExtensionBuilder {
pub fn js(&mut self, js_files: Vec<ExtensionFileSource>) -> &mut Self { pub fn js(&mut self, js_files: Vec<ExtensionFileSource>) -> &mut Self {
let js_files =
// TODO(bartlomieju): if we're automatically remapping here, then we should
// use a different result struct that `ExtensionFileSource` as it's confusing
// when (and why) the remapping happens.
js_files.into_iter().map(|file_source| ExtensionFileSource {
specifier: format!("ext:{}/{}", self.name, file_source.specifier),
code: file_source.code,
});
self.js.extend(js_files); self.js.extend(js_files);
self self
} }
pub fn esm(&mut self, esm_files: Vec<ExtensionFileSource>) -> &mut Self { pub fn esm(&mut self, esm_files: Vec<ExtensionFileSource>) -> &mut Self {
let esm_files = esm_files
.into_iter()
// TODO(bartlomieju): if we're automatically remapping here, then we should
// use a different result struct that `ExtensionFileSource` as it's confusing
// when (and why) the remapping happens.
.map(|file_source| ExtensionFileSource {
specifier: format!("ext:{}/{}", self.name, file_source.specifier),
code: file_source.code,
});
self.esm.extend(esm_files); self.esm.extend(esm_files);
self self
} }
@ -567,10 +584,10 @@ impl ExtensionBuilder {
#[cfg(not(feature = "include_js_files_for_snapshotting"))] #[cfg(not(feature = "include_js_files_for_snapshotting"))]
#[macro_export] #[macro_export]
macro_rules! include_js_files { macro_rules! include_js_files {
($name:ident dir $dir:literal, $($file:literal,)+) => { (dir $dir:literal, $($file:literal,)+) => {
vec![ vec![
$($crate::ExtensionFileSource { $($crate::ExtensionFileSource {
specifier: concat!("ext:", stringify!($name), "/", $file), specifier: concat!($file).to_string(),
code: $crate::ExtensionFileSourceCode::IncludedInBinary( code: $crate::ExtensionFileSourceCode::IncludedInBinary(
include_str!(concat!($dir, "/", $file) include_str!(concat!($dir, "/", $file)
)), )),
@ -578,10 +595,10 @@ macro_rules! include_js_files {
] ]
}; };
($name:ident $($file:literal,)+) => { ($($file:literal,)+) => {
vec![ vec![
$($crate::ExtensionFileSource { $($crate::ExtensionFileSource {
specifier: concat!("ext:", stringify!($name), "/", $file), specifier: $file.to_string(),
code: $crate::ExtensionFileSourceCode::IncludedInBinary( code: $crate::ExtensionFileSourceCode::IncludedInBinary(
include_str!($file) include_str!($file)
), ),
@ -593,10 +610,10 @@ macro_rules! include_js_files {
#[cfg(feature = "include_js_files_for_snapshotting")] #[cfg(feature = "include_js_files_for_snapshotting")]
#[macro_export] #[macro_export]
macro_rules! include_js_files { macro_rules! include_js_files {
($name:ident dir $dir:literal, $($file:literal,)+) => { (dir $dir:literal, $($file:literal,)+) => {
vec![ vec![
$($crate::ExtensionFileSource { $($crate::ExtensionFileSource {
specifier: concat!("ext:", stringify!($name), "/", $file), specifier: concat!($file).to_string(),
code: $crate::ExtensionFileSourceCode::LoadedFromFsDuringSnapshot( code: $crate::ExtensionFileSourceCode::LoadedFromFsDuringSnapshot(
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join($dir).join($file) std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join($dir).join($file)
), ),
@ -604,10 +621,10 @@ macro_rules! include_js_files {
] ]
}; };
($name:ident $($file:literal,)+) => { ($($file:literal,)+) => {
vec![ vec![
$($crate::ExtensionFileSource { $($crate::ExtensionFileSource {
specifier: concat!("ext:", stringify!($name), "/", $file), specifier: $file.to_string(),
code: $crate::ExtensionFileSourceCode::LoadedFromFsDuringSnapshot( code: $crate::ExtensionFileSourceCode::LoadedFromFsDuringSnapshot(
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join($file) std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join($file)
), ),

View file

@ -432,7 +432,7 @@ impl ModuleLoader for ExtModuleLoader {
if let Some(file_source) = maybe_file_source { if let Some(file_source) = maybe_file_source {
{ {
let mut used_esm_sources = self.used_esm_sources.borrow_mut(); let mut used_esm_sources = self.used_esm_sources.borrow_mut();
let used = used_esm_sources.get_mut(file_source.specifier).unwrap(); let used = used_esm_sources.get_mut(&file_source.specifier).unwrap();
*used = true; *used = true;
} }
@ -1047,23 +1047,13 @@ impl ModuleMap {
let main = v8::Boolean::new(scope, info.main); let main = v8::Boolean::new(scope, info.main);
module_info_arr.set_index(scope, 1, main.into()); module_info_arr.set_index(scope, 1, main.into());
let name = v8::String::new_from_one_byte( let name = v8::String::new(scope, &info.name).unwrap();
scope,
info.name.as_bytes(),
v8::NewStringType::Normal,
)
.unwrap();
module_info_arr.set_index(scope, 2, name.into()); module_info_arr.set_index(scope, 2, name.into());
let array_len = 2 * info.requests.len() as i32; let array_len = 2 * info.requests.len() as i32;
let requests_arr = v8::Array::new(scope, array_len); let requests_arr = v8::Array::new(scope, array_len);
for (i, request) in info.requests.iter().enumerate() { for (i, request) in info.requests.iter().enumerate() {
let specifier = v8::String::new_from_one_byte( let specifier = v8::String::new(scope, &request.specifier).unwrap();
scope,
request.specifier.as_bytes(),
v8::NewStringType::Normal,
)
.unwrap();
requests_arr.set_index(scope, 2 * i as u32, specifier.into()); requests_arr.set_index(scope, 2 * i as u32, specifier.into());
let asserted_module_type = let asserted_module_type =
@ -1089,12 +1079,7 @@ impl ModuleMap {
let arr = v8::Array::new(scope, 3); let arr = v8::Array::new(scope, 3);
let (specifier, asserted_module_type) = elem.0; let (specifier, asserted_module_type) = elem.0;
let specifier = v8::String::new_from_one_byte( let specifier = v8::String::new(scope, specifier).unwrap();
scope,
specifier.as_bytes(),
v8::NewStringType::Normal,
)
.unwrap();
arr.set_index(scope, 0, specifier.into()); arr.set_index(scope, 0, specifier.into());
let asserted_module_type = let asserted_module_type =
@ -1103,12 +1088,7 @@ impl ModuleMap {
let symbolic_module: v8::Local<v8::Value> = match &elem.1 { let symbolic_module: v8::Local<v8::Value> = match &elem.1 {
SymbolicModule::Alias(alias) => { SymbolicModule::Alias(alias) => {
let alias = v8::String::new_from_one_byte( let alias = v8::String::new(scope, alias).unwrap();
scope,
alias.as_bytes(),
v8::NewStringType::Normal,
)
.unwrap();
alias.into() alias.into()
} }
SymbolicModule::Mod(id) => { SymbolicModule::Mod(id) => {

View file

@ -712,7 +712,7 @@ impl JsRuntime {
futures::executor::block_on(async { futures::executor::block_on(async {
let id = runtime let id = runtime
.load_side_module( .load_side_module(
&ModuleSpecifier::parse(file_source.specifier)?, &ModuleSpecifier::parse(&file_source.specifier)?,
None, None,
) )
.await?; .await?;
@ -748,7 +748,7 @@ impl JsRuntime {
// TODO(@AaronO): use JsRuntime::execute_static() here to move src off heap // TODO(@AaronO): use JsRuntime::execute_static() here to move src off heap
realm.execute_script( realm.execute_script(
self.v8_isolate(), self.v8_isolate(),
file_source.specifier, &file_source.specifier,
&file_source.code.load()?, &file_source.code.load()?,
)?; )?;
} }

View file

@ -15,7 +15,7 @@ fn setup() -> Vec<Extension> {
deno_url::deno_url::init_ops_and_esm(), deno_url::deno_url::init_ops_and_esm(),
Extension::builder("bench_setup") Extension::builder("bench_setup")
.esm(vec![ExtensionFileSource { .esm(vec![ExtensionFileSource {
specifier: "ext:bench_setup/setup", specifier: "ext:setup".to_string(),
code: ExtensionFileSourceCode::IncludedInBinary( code: ExtensionFileSourceCode::IncludedInBinary(
r#"import { URL } from "ext:deno_url/00_url.js"; r#"import { URL } from "ext:deno_url/00_url.js";
globalThis.URL = URL; globalThis.URL = URL;

View file

@ -33,7 +33,7 @@ fn setup() -> Vec<Extension> {
), ),
Extension::builder("bench_setup") Extension::builder("bench_setup")
.esm(vec![ExtensionFileSource { .esm(vec![ExtensionFileSource {
specifier: "ext:bench_setup/setup", specifier: "ext:setup".to_string(),
code: ExtensionFileSourceCode::IncludedInBinary( code: ExtensionFileSourceCode::IncludedInBinary(
r#" r#"
import { TextDecoder } from "ext:deno_web/08_text_encoding.js"; import { TextDecoder } from "ext:deno_web/08_text_encoding.js";

View file

@ -29,7 +29,7 @@ fn setup() -> Vec<Extension> {
Extension::builder("bench_setup") Extension::builder("bench_setup")
.esm(vec![ .esm(vec![
ExtensionFileSource { ExtensionFileSource {
specifier: "ext:bench_setup/setup", specifier: "ext:setup".to_string(),
code: ExtensionFileSourceCode::IncludedInBinary(r#" code: ExtensionFileSourceCode::IncludedInBinary(r#"
import { setTimeout, handleTimerMacrotask } from "ext:deno_web/02_timers.js"; import { setTimeout, handleTimerMacrotask } from "ext:deno_web/02_timers.js";
globalThis.setTimeout = setTimeout; globalThis.setTimeout = setTimeout;

View file

@ -14,7 +14,7 @@ fn setup() -> Vec<Extension> {
deno_webidl::deno_webidl::init_ops_and_esm(), deno_webidl::deno_webidl::init_ops_and_esm(),
Extension::builder("deno_webidl_bench") Extension::builder("deno_webidl_bench")
.esm(vec![ExtensionFileSource { .esm(vec![ExtensionFileSource {
specifier: "ext/deno_webidl_bench:setup", specifier: "ext:setup".to_string(),
code: ExtensionFileSourceCode::IncludedInBinary(include_str!( code: ExtensionFileSourceCode::IncludedInBinary(include_str!(
"dict.js" "dict.js"
)), )),

View file

@ -248,7 +248,7 @@ mod startup_snapshot {
deps = [runtime], deps = [runtime],
customizer = |ext: &mut deno_core::ExtensionBuilder| { customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.esm(vec![ExtensionFileSource { ext.esm(vec![ExtensionFileSource {
specifier: "ext:runtime_main/js/99_main.js", specifier: "js/99_main.js".to_string(),
code: deno_core::ExtensionFileSourceCode::IncludedInBinary( code: deno_core::ExtensionFileSourceCode::IncludedInBinary(
include_str!("js/99_main.js"), include_str!("js/99_main.js"),
), ),