1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

perf: don't store duplicate info for ops in the snapshot (#27430)

Mostly for changes from https://github.com/denoland/deno_core/pull/1010

---------

Co-authored-by: David Sherret <dsherret@gmail.com>
This commit is contained in:
Bartek Iwańczuk 2024-12-20 17:43:03 +00:00 committed by GitHub
parent 65b647909d
commit c30f3450c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 29 additions and 31 deletions

12
Cargo.lock generated
View file

@ -1500,9 +1500,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_core" name = "deno_core"
version = "0.326.0" version = "0.327.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed157162dc5320a2b46ffeeaec24788339df0f2437cfaea78a8d82696715ad7f" checksum = "eaf8dff204b9c2415deb47b9f30d4d38b0925d0d88f1f9074e8e76f59e6d7ded"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"az", "az",
@ -2074,9 +2074,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_ops" name = "deno_ops"
version = "0.202.0" version = "0.203.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dd8ac1af251e292388e516dd339b9a3b982a6d1e7f8644c08e34671ca39003c" checksum = "b146ca74cac431843486ade58e2accc16c11315fb2c6934590a52a73c56b7ec3"
dependencies = [ dependencies = [
"proc-macro-rules", "proc-macro-rules",
"proc-macro2", "proc-macro2",
@ -6725,9 +6725,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_v8" name = "serde_v8"
version = "0.235.0" version = "0.236.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07afd8b67b4a442ecc2823038473ac0e9e5682de93c213323b60661afdd7eb4" checksum = "e23b3abce64010612f88f4ff689a959736f99eb3dc0dbf1c7903434b8bd8cda5"
dependencies = [ dependencies = [
"num-bigint", "num-bigint",
"serde", "serde",

View file

@ -48,7 +48,7 @@ repository = "https://github.com/denoland/deno"
[workspace.dependencies] [workspace.dependencies]
deno_ast = { version = "=0.44.0", features = ["transpiling"] } deno_ast = { version = "=0.44.0", features = ["transpiling"] }
deno_core = { version = "0.326.0" } deno_core = { version = "0.327.0" }
deno_bench_util = { version = "0.178.0", path = "./bench_util" } deno_bench_util = { version = "0.178.0", path = "./bench_util" }
deno_config = { version = "=0.40.0", features = ["workspace", "sync"] } deno_config = { version = "=0.40.0", features = ["workspace", "sync"] }

View file

@ -996,7 +996,7 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
std::future::ready(()).boxed_local() std::future::ready(()).boxed_local()
} }
fn get_source_map(&self, file_name: &str) -> Option<Vec<u8>> { fn get_source_map(&self, file_name: &str) -> Option<Cow<[u8]>> {
let specifier = resolve_url(file_name).ok()?; let specifier = resolve_url(file_name).ok()?;
match specifier.scheme() { match specifier.scheme() {
// we should only be looking for emits for schemes that denote external // we should only be looking for emits for schemes that denote external
@ -1008,7 +1008,7 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
.0 .0
.load_prepared_module_for_source_map_sync(&specifier) .load_prepared_module_for_source_map_sync(&specifier)
.ok()??; .ok()??;
source_map_from_code(source.code.as_bytes()) source_map_from_code(source.code.as_bytes()).map(Cow::Owned)
} }
fn get_source_mapped_source_line( fn get_source_mapped_source_line(

View file

@ -746,7 +746,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
for (specifier, source_map) in source_maps { for (specifier, source_map) in source_maps {
source_map_store.add( source_map_store.add(
Cow::Owned(root_dir_url.specifier_key(specifier).into_owned()), Cow::Owned(root_dir_url.specifier_key(specifier).into_owned()),
Cow::Owned(source_map), Cow::Owned(source_map.into_bytes()),
); );
} }

View file

@ -502,7 +502,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
std::future::ready(()).boxed_local() std::future::ready(()).boxed_local()
} }
fn get_source_map(&self, file_name: &str) -> Option<Vec<u8>> { fn get_source_map(&self, file_name: &str) -> Option<Cow<[u8]>> {
if file_name.starts_with("file:///") { if file_name.starts_with("file:///") {
let url = let url =
deno_path_util::url_from_directory_path(self.shared.vfs.root()).ok()?; deno_path_util::url_from_directory_path(self.shared.vfs.root()).ok()?;
@ -512,8 +512,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
} else { } else {
self.shared.source_maps.get(file_name) self.shared.source_maps.get(file_name)
} }
// todo(https://github.com/denoland/deno_core/pull/1007): don't clone .map(Cow::Borrowed)
.map(|s| s.as_bytes().to_vec())
} }
fn get_source_mapped_source_line( fn get_source_mapped_source_line(

View file

@ -86,7 +86,7 @@ pub fn serialize_binary_data_section(
builder.append_le(specifier.len() as u32); builder.append_le(specifier.len() as u32);
builder.append(specifier); builder.append(specifier);
builder.append_le(source_map.len() as u32); builder.append_le(source_map.len() as u32);
builder.append(source_map); builder.append(source_map.as_ref());
} }
} }
@ -124,9 +124,9 @@ pub fn deserialize_binary_data_section(
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
fn read_source_map_entry( fn read_source_map_entry(
input: &[u8], input: &[u8],
) -> Result<(&[u8], (Cow<str>, Cow<str>)), AnyError> { ) -> Result<(&[u8], (Cow<str>, &[u8])), AnyError> {
let (input, specifier) = read_string_lossy(input)?; let (input, specifier) = read_string_lossy(input)?;
let (input, source_map) = read_string_lossy(input)?; let (input, source_map) = read_bytes_with_u32_len(input)?;
Ok((input, (specifier, source_map))) Ok((input, (specifier, source_map)))
} }
@ -164,7 +164,7 @@ pub fn deserialize_binary_data_section(
let (current_input, (specifier, source_map)) = let (current_input, (specifier, source_map)) =
read_source_map_entry(input)?; read_source_map_entry(input)?;
input = current_input; input = current_input;
source_maps.add(specifier, source_map); source_maps.add(specifier, Cow::Borrowed(source_map));
} }
// finally ensure we read the magic bytes at the end // finally ensure we read the magic bytes at the end
@ -293,7 +293,7 @@ impl DenoCompileModuleSource {
} }
pub struct SourceMapStore { pub struct SourceMapStore {
data: IndexMap<Cow<'static, str>, Cow<'static, str>>, data: IndexMap<Cow<'static, str>, Cow<'static, [u8]>>,
} }
impl SourceMapStore { impl SourceMapStore {
@ -306,13 +306,13 @@ impl SourceMapStore {
pub fn add( pub fn add(
&mut self, &mut self,
specifier: Cow<'static, str>, specifier: Cow<'static, str>,
source_map: Cow<'static, str>, source_map: Cow<'static, [u8]>,
) { ) {
self.data.insert(specifier, source_map); self.data.insert(specifier, source_map);
} }
pub fn get(&self, specifier: &str) -> Option<&Cow<'static, str>> { pub fn get(&self, specifier: &str) -> Option<&[u8]> {
self.data.get(specifier) self.data.get(specifier).map(|v| v.as_ref())
} }
} }
@ -763,8 +763,7 @@ fn check_has_len(input: &[u8], len: usize) -> Result<(), AnyError> {
} }
fn read_string_lossy(input: &[u8]) -> Result<(&[u8], Cow<str>), AnyError> { fn read_string_lossy(input: &[u8]) -> Result<(&[u8], Cow<str>), AnyError> {
let (input, str_len) = read_u32_as_usize(input)?; let (input, data_bytes) = read_bytes_with_u32_len(input)?;
let (input, data_bytes) = read_bytes(input, str_len)?;
Ok((input, String::from_utf8_lossy(data_bytes))) Ok((input, String::from_utf8_lossy(data_bytes)))
} }

View file

@ -198,7 +198,7 @@ pub struct CoverageReport {
fn generate_coverage_report( fn generate_coverage_report(
script_coverage: &cdp::ScriptCoverage, script_coverage: &cdp::ScriptCoverage,
script_source: String, script_source: String,
maybe_source_map: &Option<Vec<u8>>, maybe_source_map: Option<&[u8]>,
output: &Option<PathBuf>, output: &Option<PathBuf>,
) -> CoverageReport { ) -> CoverageReport {
let maybe_source_map = maybe_source_map let maybe_source_map = maybe_source_map
@ -625,7 +625,7 @@ pub fn cover_files(
let coverage_report = generate_coverage_report( let coverage_report = generate_coverage_report(
&script_coverage, &script_coverage,
runtime_code.as_str().to_owned(), runtime_code.as_str().to_owned(),
&source_map, source_map.as_deref(),
&out_mode, &out_mode,
); );

View file

@ -140,23 +140,23 @@ mod tests {
#[test] #[test]
fn test_source_map_from_code() { fn test_source_map_from_code() {
let to_string = let to_string =
|bytes: Vec<u8>| -> String { String::from_utf8(bytes).unwrap() }; |bytes: Vec<u8>| -> String { String::from_utf8(bytes.to_vec()).unwrap() };
assert_eq!( assert_eq!(
source_map_from_code( source_map_from_code(
b"test\n//# sourceMappingURL=data:application/json;base64,dGVzdGluZ3Rlc3Rpbmc=", b"test\n//# sourceMappingURL=data:application/json;base64,dGVzdGluZ3Rlc3Rpbmc="
).map(to_string), ).map(to_string),
Some("testingtesting".to_string()) Some("testingtesting".to_string())
); );
assert_eq!( assert_eq!(
source_map_from_code( source_map_from_code(
b"test\n//# sourceMappingURL=data:application/json;base64,dGVzdGluZ3Rlc3Rpbmc=\n \n", b"test\n//# sourceMappingURL=data:application/json;base64,dGVzdGluZ3Rlc3Rpbmc=\n \n"
).map(to_string), ).map(to_string),
Some("testingtesting".to_string()) Some("testingtesting".to_string())
); );
assert_eq!( assert_eq!(
source_map_from_code( source_map_from_code(
b"test\n//# sourceMappingURL=data:application/json;base64,dGVzdGluZ3Rlc3Rpbmc=\n test\n", b"test\n//# sourceMappingURL=data:application/json;base64,dGVzdGluZ3Rlc3Rpbmc=\n test\n"
), ).map(to_string),
None None
); );
assert_eq!( assert_eq!(
@ -164,7 +164,7 @@ mod tests {
b"\"use strict\"; b"\"use strict\";
throw new Error(\"Hello world!\"); throw new Error(\"Hello world!\");
//# sourceMappingURL=data:application/json;base64,{", //# sourceMappingURL=data:application/json;base64,{"
), ),
None None
); );