Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
5 changes: 3 additions & 2 deletions cli/module_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1008,7 +1008,8 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
.0
.load_prepared_module_for_source_map_sync(&specifier)
.ok()??;
source_map_from_code(source.code.as_bytes())
let data = source.code.as_bytes().to_vec();
dsherret marked this conversation as resolved.
Show resolved Hide resolved
source_map_from_code(data.into())
}

fn get_source_mapped_source_line(
Expand Down
5 changes: 2 additions & 3 deletions cli/standalone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand All @@ -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(move |s| s.as_bytes().into())
}

fn get_source_mapped_source_line(
Expand Down
5 changes: 3 additions & 2 deletions cli/tools/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use deno_core::url::Url;
use deno_core::LocalInspectorSession;
use node_resolver::InNpmPackageChecker;
use regex::Regex;
use std::borrow::Cow;
use std::fs;
use std::fs::File;
use std::io::BufWriter;
Expand Down Expand Up @@ -198,7 +199,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<Cow<[u8]>>,
output: &Option<PathBuf>,
) -> CoverageReport {
let maybe_source_map = maybe_source_map
Expand Down Expand Up @@ -621,7 +622,7 @@ pub fn cover_files(
None => original_source.to_string(),
};

let source_map = source_map_from_code(runtime_code.as_bytes());
let source_map = source_map_from_code(runtime_code.as_bytes().into());
let coverage_report = generate_coverage_report(
&script_coverage,
runtime_code.as_str().to_owned(),
Expand Down
20 changes: 11 additions & 9 deletions cli/util/text_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ pub fn from_utf8_lossy_owned(bytes: Vec<u8>) -> String {
}
}

pub fn source_map_from_code(code: &[u8]) -> Option<Vec<u8>> {
let range = find_source_map_range(code)?;
pub fn source_map_from_code(code: Cow<[u8]>) -> Option<Cow<[u8]>> {
let range = find_source_map_range(&code)?;
let source_map_range = &code[range];
let input = source_map_range.split_at(SOURCE_MAP_PREFIX.len()).1;
let decoded_map = BASE64_STANDARD.decode(input).ok()?;
Some(decoded_map)
Some(decoded_map.into())
}

/// Truncate the source code before the source map.
Expand Down Expand Up @@ -139,23 +139,24 @@ mod tests {

#[test]
fn test_source_map_from_code() {
let to_string =
|bytes: Vec<u8>| -> String { String::from_utf8(bytes).unwrap() };
let to_string = |bytes: Cow<[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=".into(),
).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".into(),
).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".into(),
),
None
);
Expand All @@ -164,7 +165,8 @@ mod tests {
b"\"use strict\";

throw new Error(\"Hello world!\");
//# sourceMappingURL=data:application/json;base64,{",
//# sourceMappingURL=data:application/json;base64,{"
.into(),
),
None
);
Expand Down
Loading