From 98ada1e8ff984abdd794a658e9a26989f936bb71 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Thu, 19 Nov 2026 10:37:00 +0100 Subject: [PATCH] Watch Folder renders take the host's memory budget; docs and test comment (#3941 review) --- apps/effectcraft-cli/tests/it/cli.rs | 15 ++++++++++++ crates/engine/src/cmd/watch_folder.rs | 3 +++ crates/engine/src/rq_tests.rs | 4 ++-- crates/engine/src/tests/m137.rs | 33 +++++++++++++++++++++++++++ docs/preferences.md | 10 ++++---- 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/apps/effectcraft-cli/tests/it/cli.rs b/apps/effectcraft-cli/tests/it/cli.rs index 4510f16c9..3bdda82a7 100644 --- a/apps/effectcraft-cli/tests/it/cli.rs +++ b/apps/effectcraft-cli/tests/it/cli.rs @@ -40,6 +40,21 @@ fn tmp(name: &str) -> PathBuf { canonical(&d).unwrap_or(d).join(name) } +/// #3941: a command-line session reads the system's memory at start, so its caches share the +/// budget of the installed RAM (as in the desktop app), not the budget for unknown RAM. +#[test] +fn the_caches_follow_the_installed_ram() { + let Some(memory) = effectcraft_engine::sysinfo::memory() else { + eprintln!("the system's memory can't be read here: not checked"); + return; + }; + let v = ok_json(&["exec", "help.systemReport", r#"{"quiet":true}"#, "--empty"]); + let reduced = v["caches"]["reduced"].as_bool().unwrap(); + let want = effectcraft_engine::prefs::Prefs::default().memory_budget(Some(memory), reduced).bytes; + let gb = |b: usize| format!("{:.1} GB", b as f64 / (1u64 << 30) as f64); + assert_eq!(v["caches"]["budget"], gb(want), "{v}"); +} + #[test] fn info_and_commands() { let v = ok_json(&["info"]); diff --git a/crates/engine/src/cmd/watch_folder.rs b/crates/engine/src/cmd/watch_folder.rs index b8d476d0b..682cb49ab 100644 --- a/crates/engine/src/cmd/watch_folder.rs +++ b/crates/engine/src/cmd/watch_folder.rs @@ -65,6 +65,9 @@ fn render_project(host: &Session, path: &Path) -> Value { s.exporter = host.exporter.clone(); s.accel = host.accel.clone(); s.prefs = host.prefs.clone(); + // Its Render Queue caches take the host's memory budget (#3941), which follows its reading. + s.sys_memory = host.sys_memory; + s.memory_low = host.memory_low; let result = (|| -> std::result::Result { s.execute("file.open", json!({"path": name})).map_err(|e| e.to_string())?; let queued = s.project.render_queue.iter().filter(|i| i.render && i.status == RenderStatus::Queued).count(); diff --git a/crates/engine/src/rq_tests.rs b/crates/engine/src/rq_tests.rs index 0c6c611ff..124ef9518 100644 --- a/crates/engine/src/rq_tests.rs +++ b/crates/engine/src/rq_tests.rs @@ -309,8 +309,8 @@ fn a_queue_run_keeps_its_jobs_warm() { #[test] fn render_queue_runs_and_one_off_exports_follow_the_memory_budget() { - // #3941: a Render Queue run's two layer caches held 512 MiB together and a one-off export's - // 512 MiB each, whatever the memory budget. Both follow the session's budget now. + // #3941: a Render Queue run's two layer caches and a one-off export's held 512 MiB each + // (1 GiB together), whatever the memory budget. Both follow the session's budget now. type Seen = (Option<(usize, usize)>, Option); struct Budgets(Mutex>); impl Exporter for Budgets { diff --git a/crates/engine/src/tests/m137.rs b/crates/engine/src/tests/m137.rs index 13abe9c64..d0857280a 100644 --- a/crates/engine/src/tests/m137.rs +++ b/crates/engine/src/tests/m137.rs @@ -58,6 +58,39 @@ fn watch_folder_renders_queued_projects_and_writes_status() { assert!(host.execute("file.watchFolder", json!({"folder": "/no/such/folder"})).is_err()); } +#[test] +fn a_watch_folder_render_takes_the_hosts_memory_budget() { + // #3941: the Watch Folder renders each project in a session of its own, which had no memory + // reading: its Render Queue caches took the budget for unknown RAM, not the host's. + use crate::{ExportJob, ExportResult, Exporter}; + use effectcraft_project::render_queue::OutputFormat; + struct Budgets(std::sync::Mutex>>); + impl Exporter for Budgets { + fn formats(&self) -> Vec { + OutputFormat::ALL.to_vec() + } + fn export(&self, job: &ExportJob, _: &mut dyn FnMut(u64, u64) -> bool) -> Result { + self.0.lock().unwrap().push(job.caches.map(|c| c.gpu.budget())); + Ok(ExportResult { path: job.path.to_string(), ..Default::default() }) + } + } + let dir = out_dir("watch-folder-budget"); + let ex = Arc::new(Budgets(Default::default())); + let mut a = Session { exporter: Some(ex.clone()), ..Default::default() }; + a.execute("comp.new", json!({"name": "Shot", "width": 32, "height": 32, "frameRate": 10, "duration": 0.5})).unwrap(); + a.execute("renderQueue.add", json!({})).unwrap(); + a.execute("file.saveAs", json!({"path": dir.join("a.ecproj").to_string_lossy()})).unwrap(); + + let mut host = Session { exporter: Some(ex.clone()), ..Default::default() }; + // A 64 GB machine: 46.4 GB with the default reserve. + host.take_memory_reading(Some(crate::sysinfo::SysMemory { total: 64 << 30, available: 48 << 30 })); + let budget = host.export_cache_budget(); + assert_ne!(budget as u64, crate::prefs::FALLBACK_MEMORY_BUDGET); + host.execute("file.watchFolder", json!({"folder": dir.to_string_lossy()})).unwrap(); + host.execute("file.watchFolder", json!({"stop": true})).unwrap(); + assert_eq!(*ex.0.lock().unwrap(), vec![Some(budget)]); +} + #[test] fn vanishing_point_import_is_disabled_with_a_reason() { let mut s = Session::default(); diff --git a/docs/preferences.md b/docs/preferences.md index 853199c14..04f1415f1 100644 --- a/docs/preferences.md +++ b/docs/preferences.md @@ -192,13 +192,15 @@ Commands (CLI, MCP, control channel): cache's reserve free on their disk; earlier sessions' copies are adopted. The Disk page shows the local copies, what is queued and being copied, and the network locations - `memory.ramReservedGb`: RAM Reserved for Other Applications, the one memory setting (After - Effects has a setting of this name too). EffectCraft's big caches (processed layers, decoded - footage frames, decoded OpenEXR planes, RAM preview frames, and the disk cache's write queue) - share one budget: 80 % of the installed RAM left after the reserve. The other 20 % is room for + Effects has a setting of this name too). EffectCraft's big caches (processed layers, also those + of exports and Render Queue runs, decoded footage frames, decoded OpenEXR planes, RAM preview + frames, and the disk cache's write queue) share one budget: 80 % of the installed RAM left + after the reserve. The command-line tool and its MCP server read the installed RAM once at start + (with the default reserve: they don't read the app's settings). The other 20 % is room for EffectCraft's own working memory (decoders, render buffers, undo, GPU staging, the interface). With the default 6 GB reserved that is 8.0 GB on a 16 GB machine, 46.4 GB on 64 GB and 97.6 GB on 128 GB. The budget is at least 192 MB for all caches together; while the installed RAM is - unknown (a sandbox, the CLI, or the desktop before its first reading) it is 5 GB, in the browser 3.5 GB + unknown (a sandbox, or the desktop before its first reading) it is 5 GB, in the browser 3.5 GB (with the RAM preview at most 3 GB there). No cache has a share of its own: when they hold more than the budget together, the memory accountant frees the least valuable data first, whichever cache holds it, down to 90 % of the budget. An item's value is what it would cost to