Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

bundle: the copies' lookup is one closure, shorter notes (dupes, size)

shinyobjectz9a289e072c36
diff --git a/runtime/bundle/src/cache.rs b/runtime/bundle/src/cache.rs
index 00371c5f..a666c5a1 100644
--- a/runtime/bundle/src/cache.rs
+++ b/runtime/bundle/src/cache.rs
@@ -89,8 +89,7 @@ pub fn export_cache(tsx: &Path, js: &Path, out: &Path, args: &[String]) -> Optio
// never a stale export)
let text = String::from_utf8_lossy(&bundle);
let made: std::collections::HashSet<PathBuf> = std::fs::read_to_string(root.join("outputs.list")).unwrap_or_default().lines().map(PathBuf::from).collect();
- // (a file is one of them only if its name is one of theirs, or it is a link to one: only those are resolved, where
- // every file under the edit's folder was, thousands of them before a render's first frame)
+ // (a file is one of them only if its name is one of theirs, or it is a link to one: only those are resolved)
let names: std::collections::HashSet<&std::ffi::OsStr> = made.iter().filter_map(|m| m.file_name()).collect();
let may_be_made = |p: &Path| p.file_name().is_some_and(|n| names.contains(n)) || p.symlink_metadata().is_ok_and(|m| m.file_type().is_symlink());
files.retain(|p| !may_be_made(p) || !made.contains(&std::fs::canonicalize(p).unwrap_or_else(|_| p.clone())) || p.file_stem().is_some_and(|n| text.contains(&*n.to_string_lossy())));
@@ -103,10 +102,8 @@ pub fn export_cache(tsx: &Path, js: &Path, out: &Path, args: &[String]) -> Optio
files.push(std::env::current_exe().ok().and_then(|e| std::fs::canonicalize(e).ok())?);
files.sort();
files.dedup();
- // the optimized copies there are, listed once. Asking each media file for its own (raea_io_media::mezz::has and
- // ranges) read the file's first and last MiB and listed this folder again, for every picture, sound and video
- // under the edit's folder: 492 files in one real project and 2,417 in another, before a render's first frame.
- // Only a video has copies, and with none in the folder no file has one
+ // the optimized copies there are, listed once: asking each media file for its own read its first and last MiB and
+ // listed this folder again (2,417 files in one real project, before a render's first frame). Only a video has any
let copies: Vec<String> = std::fs::read_dir(raea_io_media::mezz::dir()).map(|d| d.flatten().map(|e| e.file_name().to_string_lossy().into_owned()).collect()).unwrap_or_default();
for p in &files {
eat(p.as_os_str().as_encoded_bytes());
@@ -121,14 +118,13 @@ pub fn export_cache(tsx: &Path, js: &Path, out: &Path, args: &[String]) -> Optio
// the source (raea_io_media::mezz)
let video = matches!(p.extension().and_then(|x| x.to_str()).unwrap_or("").to_ascii_lowercase().as_str(), "mp4" | "mov" | "m4v");
if video && !copies.is_empty() && let Some(fp) = raea_io_media::mezz::fingerprint(p) {
- if copies.iter().any(|n| n.strip_prefix(fp.as_str()).is_some_and(|rest| rest.starts_with('.') && !rest.contains("partial"))) {
+ // its whole copy (FP.EXT) and its range copies ([email protected]): the frames inside them come from the copies
+ let named = |mark: char| copies.iter().any(|n| n.strip_prefix(fp.as_str()).is_some_and(|rest| rest.starts_with(mark) && !rest.contains("partial")));
+ if named('.') {
eat(b"mezz");
}
- // its range copies too: the frames inside them come from the copies
- if copies.iter().any(|n| n.strip_prefix(fp.as_str()).is_some_and(|rest| rest.starts_with('@'))) {
- for r in raea_io_media::mezz::ranges(p) {
- eat(format!("mezz@{}-{}", r.first, r.last).as_bytes());
- }
+ for r in named('@').then(|| raea_io_media::mezz::ranges(p)).unwrap_or_default() {
+ eat(format!("mezz@{}-{}", r.first, r.last).as_bytes());
}
}
}
diff --git a/runtime/bundle/src/rewrite.rs b/runtime/bundle/src/rewrite.rs
index 932dadcd..5420371c 100644
--- a/runtime/bundle/src/rewrite.rs
+++ b/runtime/bundle/src/rewrite.rs
@@ -126,9 +126,8 @@ pub fn sources(root: &Path) -> R<Vec<PathBuf>> {
let mut stack = vec![root.to_path_buf()];
while let Some(d) = stack.pop() {
for e in std::fs::read_dir(&d).map_err(|e| format!("{}: {e}", d.display()))?.flatten() {
- // what copy_dir leaves out is no source of the edit's: a project's .git, node_modules and target were
- // walked whole here, each entry asked what it is (2 s before a render's first frame in a project of ten
- // thousand files, bundle cached or not)
+ // what copy_dir leaves out is no source of the edit's (a project's .git and node_modules were walked whole:
+ // 2 s before a render's first frame in a project of ten thousand files)
let name = e.file_name();
if name.to_string_lossy().starts_with('.') || name == "node_modules" || name == "target" {
continue;