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:
parent
65b647909d
commit
c30f3450c6
8 changed files with 29 additions and 31 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -1500,9 +1500,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_core"
|
||||
version = "0.326.0"
|
||||
version = "0.327.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed157162dc5320a2b46ffeeaec24788339df0f2437cfaea78a8d82696715ad7f"
|
||||
checksum = "eaf8dff204b9c2415deb47b9f30d4d38b0925d0d88f1f9074e8e76f59e6d7ded"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"az",
|
||||
|
@ -2074,9 +2074,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_ops"
|
||||
version = "0.202.0"
|
||||
version = "0.203.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4dd8ac1af251e292388e516dd339b9a3b982a6d1e7f8644c08e34671ca39003c"
|
||||
checksum = "b146ca74cac431843486ade58e2accc16c11315fb2c6934590a52a73c56b7ec3"
|
||||
dependencies = [
|
||||
"proc-macro-rules",
|
||||
"proc-macro2",
|
||||
|
@ -6725,9 +6725,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_v8"
|
||||
version = "0.235.0"
|
||||
version = "0.236.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d07afd8b67b4a442ecc2823038473ac0e9e5682de93c213323b60661afdd7eb4"
|
||||
checksum = "e23b3abce64010612f88f4ff689a959736f99eb3dc0dbf1c7903434b8bd8cda5"
|
||||
dependencies = [
|
||||
"num-bigint",
|
||||
"serde",
|
||||
|
|
|
@ -48,7 +48,7 @@ repository = "https://github.com/denoland/deno"
|
|||
|
||||
[workspace.dependencies]
|
||||
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_config = { version = "=0.40.0", features = ["workspace", "sync"] }
|
||||
|
|
|
@ -996,7 +996,7 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
|
|||
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()?;
|
||||
match specifier.scheme() {
|
||||
// we should only be looking for emits for schemes that denote external
|
||||
|
@ -1008,7 +1008,7 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
|
|||
.0
|
||||
.load_prepared_module_for_source_map_sync(&specifier)
|
||||
.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(
|
||||
|
|
|
@ -746,7 +746,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
|
|||
for (specifier, source_map) in source_maps {
|
||||
source_map_store.add(
|
||||
Cow::Owned(root_dir_url.specifier_key(specifier).into_owned()),
|
||||
Cow::Owned(source_map),
|
||||
Cow::Owned(source_map.into_bytes()),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -502,7 +502,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
|
|||
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:///") {
|
||||
let url =
|
||||
deno_path_util::url_from_directory_path(self.shared.vfs.root()).ok()?;
|
||||
|
@ -512,8 +512,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
|
|||
} else {
|
||||
self.shared.source_maps.get(file_name)
|
||||
}
|
||||
// todo(https://github.com/denoland/deno_core/pull/1007): don't clone
|
||||
.map(|s| s.as_bytes().to_vec())
|
||||
.map(Cow::Borrowed)
|
||||
}
|
||||
|
||||
fn get_source_mapped_source_line(
|
||||
|
|
|
@ -86,7 +86,7 @@ pub fn serialize_binary_data_section(
|
|||
builder.append_le(specifier.len() as u32);
|
||||
builder.append(specifier);
|
||||
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)]
|
||||
fn read_source_map_entry(
|
||||
input: &[u8],
|
||||
) -> Result<(&[u8], (Cow<str>, Cow<str>)), AnyError> {
|
||||
) -> Result<(&[u8], (Cow<str>, &[u8])), AnyError> {
|
||||
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)))
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ pub fn deserialize_binary_data_section(
|
|||
let (current_input, (specifier, source_map)) =
|
||||
read_source_map_entry(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
|
||||
|
@ -293,7 +293,7 @@ impl DenoCompileModuleSource {
|
|||
}
|
||||
|
||||
pub struct SourceMapStore {
|
||||
data: IndexMap<Cow<'static, str>, Cow<'static, str>>,
|
||||
data: IndexMap<Cow<'static, str>, Cow<'static, [u8]>>,
|
||||
}
|
||||
|
||||
impl SourceMapStore {
|
||||
|
@ -306,13 +306,13 @@ impl SourceMapStore {
|
|||
pub fn add(
|
||||
&mut self,
|
||||
specifier: Cow<'static, str>,
|
||||
source_map: Cow<'static, str>,
|
||||
source_map: Cow<'static, [u8]>,
|
||||
) {
|
||||
self.data.insert(specifier, source_map);
|
||||
}
|
||||
|
||||
pub fn get(&self, specifier: &str) -> Option<&Cow<'static, str>> {
|
||||
self.data.get(specifier)
|
||||
pub fn get(&self, specifier: &str) -> Option<&[u8]> {
|
||||
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> {
|
||||
let (input, str_len) = read_u32_as_usize(input)?;
|
||||
let (input, data_bytes) = read_bytes(input, str_len)?;
|
||||
let (input, data_bytes) = read_bytes_with_u32_len(input)?;
|
||||
Ok((input, String::from_utf8_lossy(data_bytes)))
|
||||
}
|
||||
|
||||
|
|
|
@ -198,7 +198,7 @@ pub struct CoverageReport {
|
|||
fn generate_coverage_report(
|
||||
script_coverage: &cdp::ScriptCoverage,
|
||||
script_source: String,
|
||||
maybe_source_map: &Option<Vec<u8>>,
|
||||
maybe_source_map: Option<&[u8]>,
|
||||
output: &Option<PathBuf>,
|
||||
) -> CoverageReport {
|
||||
let maybe_source_map = maybe_source_map
|
||||
|
@ -625,7 +625,7 @@ pub fn cover_files(
|
|||
let coverage_report = generate_coverage_report(
|
||||
&script_coverage,
|
||||
runtime_code.as_str().to_owned(),
|
||||
&source_map,
|
||||
source_map.as_deref(),
|
||||
&out_mode,
|
||||
);
|
||||
|
||||
|
|
|
@ -140,23 +140,23 @@ mod tests {
|
|||
#[test]
|
||||
fn test_source_map_from_code() {
|
||||
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!(
|
||||
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),
|
||||
Some("testingtesting".to_string())
|
||||
);
|
||||
assert_eq!(
|
||||
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),
|
||||
Some("testingtesting".to_string())
|
||||
);
|
||||
assert_eq!(
|
||||
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
|
||||
);
|
||||
assert_eq!(
|
||||
|
@ -164,7 +164,7 @@ mod tests {
|
|||
b"\"use strict\";
|
||||
|
||||
throw new Error(\"Hello world!\");
|
||||
//# sourceMappingURL=data:application/json;base64,{",
|
||||
//# sourceMappingURL=data:application/json;base64,{"
|
||||
),
|
||||
None
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue