mirror of
https://github.com/denoland/deno.git
synced 2025-09-25 03:42:30 +00:00
feat(compile): show remote modules and metadata size when compiling (#27415)
Co-authored-by: David Sherret <dsherret@gmail.com>
This commit is contained in:
parent
be703b7878
commit
b70aba6bae
8 changed files with 59 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
||||||
// Copyright 2018-2025 the Deno authors. MIT license.
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::cell::Cell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
@ -699,7 +700,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
|
||||||
vfs_case_sensitivity: vfs.case_sensitivity,
|
vfs_case_sensitivity: vfs.case_sensitivity,
|
||||||
};
|
};
|
||||||
|
|
||||||
let data_section_bytes = serialize_binary_data_section(
|
let (data_section_bytes, section_sizes) = serialize_binary_data_section(
|
||||||
&metadata,
|
&metadata,
|
||||||
npm_snapshot.map(|s| s.into_serialized()),
|
npm_snapshot.map(|s| s.into_serialized()),
|
||||||
&specifier_store.for_serialization(&root_dir_url),
|
&specifier_store.for_serialization(&root_dir_url),
|
||||||
|
@ -709,6 +710,22 @@ impl<'a> DenoCompileBinaryWriter<'a> {
|
||||||
)
|
)
|
||||||
.context("Serializing binary data section.")?;
|
.context("Serializing binary data section.")?;
|
||||||
|
|
||||||
|
log::info!(
|
||||||
|
"\n{} {}",
|
||||||
|
crate::colors::bold("Files:"),
|
||||||
|
crate::util::display::human_size(section_sizes.vfs as f64)
|
||||||
|
);
|
||||||
|
log::info!(
|
||||||
|
"{} {}",
|
||||||
|
crate::colors::bold("Metadata:"),
|
||||||
|
crate::util::display::human_size(section_sizes.metadata as f64)
|
||||||
|
);
|
||||||
|
log::info!(
|
||||||
|
"{} {}\n",
|
||||||
|
crate::colors::bold("Remote modules:"),
|
||||||
|
crate::util::display::human_size(section_sizes.remote_modules as f64)
|
||||||
|
);
|
||||||
|
|
||||||
write_binary_bytes(writer, original_bin, data_section_bytes, compile_flags)
|
write_binary_bytes(writer, original_bin, data_section_bytes, compile_flags)
|
||||||
.context("Writing binary bytes")
|
.context("Writing binary bytes")
|
||||||
}
|
}
|
||||||
|
@ -912,6 +929,12 @@ fn write_binary_bytes(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct BinaryDataSectionSizes {
|
||||||
|
metadata: usize,
|
||||||
|
remote_modules: usize,
|
||||||
|
vfs: usize,
|
||||||
|
}
|
||||||
|
|
||||||
/// Binary format:
|
/// Binary format:
|
||||||
/// * d3n0l4nd
|
/// * d3n0l4nd
|
||||||
/// * <metadata_len><metadata>
|
/// * <metadata_len><metadata>
|
||||||
|
@ -930,12 +953,16 @@ fn serialize_binary_data_section(
|
||||||
redirects: &SpecifierDataStore<SpecifierId>,
|
redirects: &SpecifierDataStore<SpecifierId>,
|
||||||
remote_modules: &SpecifierDataStore<RemoteModuleEntry<'_>>,
|
remote_modules: &SpecifierDataStore<RemoteModuleEntry<'_>>,
|
||||||
vfs: &BuiltVfs,
|
vfs: &BuiltVfs,
|
||||||
) -> Result<Vec<u8>, AnyError> {
|
) -> Result<(Vec<u8>, BinaryDataSectionSizes), AnyError> {
|
||||||
let metadata = serde_json::to_string(metadata)?;
|
let metadata = serde_json::to_string(metadata)?;
|
||||||
let npm_snapshot =
|
let npm_snapshot =
|
||||||
npm_snapshot.map(serialize_npm_snapshot).unwrap_or_default();
|
npm_snapshot.map(serialize_npm_snapshot).unwrap_or_default();
|
||||||
let serialized_vfs = serde_json::to_string(&vfs.entries)?;
|
let serialized_vfs = serde_json::to_string(&vfs.entries)?;
|
||||||
|
|
||||||
|
let remote_modules_len = Cell::new(0);
|
||||||
|
let metadata_len = Cell::new(0);
|
||||||
|
let vfs_len = Cell::new(0);
|
||||||
|
|
||||||
let bytes = capacity_builder::BytesBuilder::build(|builder| {
|
let bytes = capacity_builder::BytesBuilder::build(|builder| {
|
||||||
builder.append(MAGIC_BYTES);
|
builder.append(MAGIC_BYTES);
|
||||||
// 1. Metadata
|
// 1. Metadata
|
||||||
|
@ -948,12 +975,14 @@ fn serialize_binary_data_section(
|
||||||
builder.append_le(npm_snapshot.len() as u64);
|
builder.append_le(npm_snapshot.len() as u64);
|
||||||
builder.append(&npm_snapshot);
|
builder.append(&npm_snapshot);
|
||||||
}
|
}
|
||||||
|
metadata_len.set(builder.len());
|
||||||
// 3. Specifiers
|
// 3. Specifiers
|
||||||
builder.append(specifiers);
|
builder.append(specifiers);
|
||||||
// 4. Redirects
|
// 4. Redirects
|
||||||
redirects.serialize(builder);
|
redirects.serialize(builder);
|
||||||
// 5. Remote modules
|
// 5. Remote modules
|
||||||
remote_modules.serialize(builder);
|
remote_modules.serialize(builder);
|
||||||
|
remote_modules_len.set(builder.len() - metadata_len.get());
|
||||||
// 6. VFS
|
// 6. VFS
|
||||||
{
|
{
|
||||||
builder.append_le(serialized_vfs.len() as u64);
|
builder.append_le(serialized_vfs.len() as u64);
|
||||||
|
@ -964,13 +993,21 @@ fn serialize_binary_data_section(
|
||||||
builder.append(file);
|
builder.append(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
vfs_len.set(builder.len() - remote_modules_len.get());
|
||||||
|
|
||||||
// write the magic bytes at the end so we can use it
|
// write the magic bytes at the end so we can use it
|
||||||
// to make sure we've deserialized correctly
|
// to make sure we've deserialized correctly
|
||||||
builder.append(MAGIC_BYTES);
|
builder.append(MAGIC_BYTES);
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(bytes)
|
Ok((
|
||||||
|
bytes,
|
||||||
|
BinaryDataSectionSizes {
|
||||||
|
metadata: metadata_len.get(),
|
||||||
|
remote_modules: remote_modules_len.get(),
|
||||||
|
vfs: vfs_len.get(),
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_npm_snapshot(
|
fn serialize_npm_snapshot(
|
||||||
|
|
|
@ -30,11 +30,7 @@ pub fn output_vfs(vfs: &BuiltVfs, executable_name: &str) {
|
||||||
let display_tree = vfs_as_display_tree(vfs, executable_name);
|
let display_tree = vfs_as_display_tree(vfs, executable_name);
|
||||||
display_tree.print(&mut text).unwrap(); // unwrap ok because it's writing to a string
|
display_tree.print(&mut text).unwrap(); // unwrap ok because it's writing to a string
|
||||||
log::info!("\n{}\n", deno_terminal::colors::bold("Embedded Files"));
|
log::info!("\n{}\n", deno_terminal::colors::bold("Embedded Files"));
|
||||||
log::info!("{}\n", text.trim());
|
log::info!("{}", text.trim());
|
||||||
log::info!(
|
|
||||||
"Size: {}\n",
|
|
||||||
human_size(vfs.files.iter().map(|f| f.len() as f64).sum())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vfs_as_display_tree(
|
fn vfs_as_display_tree(
|
||||||
|
|
|
@ -6,5 +6,7 @@ main[WILDLINE]
|
||||||
├── file.txt ([WILDLINE])
|
├── file.txt ([WILDLINE])
|
||||||
└── main.js ([WILDLINE])
|
└── main.js ([WILDLINE])
|
||||||
|
|
||||||
Size: [WILDLINE]
|
Files: [WILDLINE]
|
||||||
|
Metadata: [WILDLINE]
|
||||||
|
Remote modules: [WILDLINE]
|
||||||
|
|
||||||
|
|
|
@ -8,5 +8,7 @@ Embedded Files
|
||||||
out[WILDLINE]
|
out[WILDLINE]
|
||||||
└── main.ts ([WILDLINE])
|
└── main.ts ([WILDLINE])
|
||||||
|
|
||||||
Size: [WILDLINE]
|
Files: [WILDLINE]
|
||||||
|
Metadata: [WILDLINE]
|
||||||
|
Remote modules: [WILDLINE]
|
||||||
|
|
||||||
|
|
|
@ -45,5 +45,7 @@ main[WILDLINE]
|
||||||
│ └── yargs-parser/18.1.3/* ([WILDLINE])
|
│ └── yargs-parser/18.1.3/* ([WILDLINE])
|
||||||
└── main.ts ([WILDLINE])
|
└── main.ts ([WILDLINE])
|
||||||
|
|
||||||
Size: [WILDLINE]
|
Files: [WILDLINE]
|
||||||
|
Metadata: [WILDLINE]
|
||||||
|
Remote modules: [WILDLINE]
|
||||||
|
|
||||||
|
|
|
@ -7,5 +7,7 @@ main[WILDLINE]
|
||||||
├── link.js --> index.js
|
├── link.js --> index.js
|
||||||
└── setup.js ([WILDLINE])
|
└── setup.js ([WILDLINE])
|
||||||
|
|
||||||
Size: [WILDLINE]
|
Files: [WILDLINE]
|
||||||
|
Metadata: [WILDLINE]
|
||||||
|
Remote modules: [WILDLINE]
|
||||||
|
|
||||||
|
|
|
@ -6,5 +6,7 @@ main[WILDLINE]
|
||||||
├── main.ts ([WILDLINE])
|
├── main.ts ([WILDLINE])
|
||||||
└── node_modules/* ([WILDLINE])
|
└── node_modules/* ([WILDLINE])
|
||||||
|
|
||||||
Size: [WILDLINE]
|
Files: [WILDLINE]
|
||||||
|
Metadata: [WILDLINE]
|
||||||
|
Remote modules: [WILDLINE]
|
||||||
|
|
||||||
|
|
|
@ -13,5 +13,7 @@ bin[WILDLINE]
|
||||||
│ └── node_modules/* ([WILDLINE])
|
│ └── node_modules/* ([WILDLINE])
|
||||||
└── some_folder/* ([WILDLINE])
|
└── some_folder/* ([WILDLINE])
|
||||||
|
|
||||||
Size: [WILDLINE]
|
Files: [WILDLINE]
|
||||||
|
Metadata: [WILDLINE]
|
||||||
|
Remote modules: [WILDLINE]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue