Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
18 changes: 13 additions & 5 deletions runtime/bundle/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ 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();
files.retain(|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())));
// (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())));
// absolute media paths the bundle names (an import from outside the edit's folder becomes its path)
for q in text.split('"').skip(1).step_by(2) {
if q.starts_with('/') && q.len() < 4096 && Path::new(q).extension().and_then(|x| x.to_str()).is_some_and(|x| MEDIA_EXTS.contains(&x.to_ascii_lowercase().as_str())) {
Expand All @@ -99,6 +102,9 @@ 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 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());
match std::fs::metadata(p) {
Expand All @@ -110,12 +116,14 @@ pub fn export_cache(tsx: &Path, js: &Path, out: &Path, args: &[String]) -> Optio
}
// which file its decoders read: a video's optimized copy, once complete, changes the pixels without touching
// the source (raea_io_media::mezz)
if MEDIA_EXTS.contains(&p.extension().and_then(|x| x.to_str()).unwrap_or("").to_ascii_lowercase().as_str()) {
if raea_io_media::mezz::has(p) {
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) {
// its whole copy (FP.EXT) and its range copies (FP@A-B.EXT): 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
for r in raea_io_media::mezz::ranges(p) {
for r in named('@').then(|| raea_io_media::mezz::ranges(p)).unwrap_or_default() {
eat(format!("mezz@{}-{}", r.first, r.last).as_bytes());
}
}
Expand Down
13 changes: 12 additions & 1 deletion runtime/bundle/src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,19 @@ 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 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;
}
let p = e.path();
if p.is_dir() {
// the entry's own kind, without another stat; a link is followed
let dir = match e.file_type() {
Ok(t) if !t.is_symlink() => t.is_dir(),
_ => p.is_dir(),
};
if dir {
stack.push(p);
} else if matches!(p.extension().and_then(|x| x.to_str()), Some("ts" | "tsx" | "js" | "jsx" | "mjs")) {
out.push(p.strip_prefix(root).unwrap().to_path_buf());
Expand Down
14 changes: 14 additions & 0 deletions runtime/bundle/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,17 @@ fn a_project_s_own_tsconfig_is_not_in_the_work_copy() {
assert!(d.join("from/tsconfig.json").exists());
let _ = std::fs::remove_dir_all(&d);
}

#[test]
fn an_edit_s_sources_leave_out_hidden_folders_and_packages() {
let d = std::env::temp_dir().join(format!("raea-bundle-sources-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&d);
for f in ["a.tsx", "parts/b.ts", ".git/hooks/c.js", "node_modules/pkg/d.js", "target/e.ts", "out/f.json"] {
std::fs::create_dir_all(d.join(f).parent().unwrap()).unwrap();
std::fs::write(d.join(f), "").unwrap();
}
let mut got = sources(&d).unwrap();
got.sort();
assert_eq!(got, vec![PathBuf::from("a.tsx"), PathBuf::from("parts/b.ts")]);
let _ = std::fs::remove_dir_all(&d);
}
2 changes: 2 additions & 0 deletions runtime/export/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub fn render(args: &[String]) -> R<String> {
unsafe { std::env::set_var("RAEA_SOURCE_STAMPS", "1") };
}
bundle_composition(&tsx, &js, &o, None)?;
raea_runtime_react::startup_mark("the composition bundled");
let wanted = match (flag(args, "--frame"), flag(args, "--at")) {
(Some(f), _) => Some(vec![f.parse().map_err(|_| "--frame takes a frame number")?]),
(_, Some(at)) => Some(at.split(',').map(|f| f.trim().parse::<i64>().map_err(|_| "--at takes frame numbers".to_string())).collect::<R<_>>()?),
Expand Down Expand Up @@ -91,6 +92,7 @@ pub fn render(args: &[String]) -> R<String> {
};
// a whole video made from these same inputs before is the export: cloned from the cache, not rendered again
let cache = if wanted.is_none() && !raea_sys_layers::on() { export_cache(&tsx, &js, &out, args) } else { None };
raea_runtime_react::startup_mark("the export cache looked up");
let manifest = MANIFEST.lock().unwrap().clone();
if let Some(c) = &cache {
// with --manifest, the manifest kept beside the export comes back too
Expand Down
13 changes: 13 additions & 0 deletions runtime/scene3d/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,13 @@ pub fn await_models(_app: &mut App) -> Result<(), String> {
#[cfg(not(target_arch = "wasm32"))]
pub fn await_models(app: &mut App) -> Result<(), String> {
let mut t0 = bevy::platform::time::Instant::now();
let t_all = t0;
let mut most = 0usize;
// the cameras off while models load, so the draws are binned once, whole (#48): raea-sys-post's views.rs
let mut off: Option<Vec<Entity>> = None;
// RAEA_MODELS_TRACE=1: each wait that ran an update says how many and for which models (a render's frame time)
let trace = std::env::var("RAEA_MODELS_TRACE").as_deref() == Ok("1");
let mut pumped = 0usize;
loop {
let world = app.world_mut();
if let Some(e) = world.resource_mut::<Error>().0.take() {
Expand All @@ -367,8 +371,17 @@ pub fn await_models(app: &mut App) -> Result<(), String> {
}
if waiting == 0 {
if let Some(cams) = off { raea_sys_post::views::on(app, cams); }
if trace && pumped > 0 {
eprintln!("raea models: waited {pumped} update(s), {:.1} ms", t_all.elapsed().as_secs_f64() * 1e3);
}
return Ok(());
}
if trace && pumped == 0 {
let mut q = app.world_mut().query::<&Model3d>();
let who: Vec<String> = q.iter(app.world()).filter(|m| !(matches!(m.state, ModelState::Ready { .. }) && m.settled())).map(|m| format!("{} ({}; surfaces {}, toon {}, shaders {})", m.id, match m.state { ModelState::Loading => "loading", ModelState::Spawned(_) => "spawned", ModelState::Ready { .. } => "ready" }, m.surfaces.len(), m.toon.len(), m.shaders.len())).take(4).collect();
eprintln!("raea models: waiting on {waiting}: {}", who.join("; "));
}
pumped += 1;
if done > most {
most = done;
t0 = bevy::platform::time::Instant::now();
Expand Down
Loading