mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-29 17:44:05 +01:00
* CLI: a headless session's footage frames keep at most 1 GB (#4157) Since #3301 the footage frames may fill the caches' whole common budget, and since #3941 the CLI's budget is that of the installed RAM. A one-pass render reads each frame about once, so it kept gigabytes of frames it never read again and was killed under a cgroup memory limit. Session::footage_cap caps the footage frames (and decoded planes) below the common budget; apply_cache_budgets honours it, so a new memory reading or a settings change keeps it. headless_session() sets it to HEADLESS_MEDIA_CACHE (1 GB, the footage cache's default in 0.24). The desktop app keeps the whole budget. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(host): a headless session's footage cap is exactly HEADLESS_MEDIA_CACHE (#4157) Assert the cap itself (or the budget, if smaller) rather than only that it is below the budget, which a wrong cap above 1 GB would also pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7e7118f1a5
commit
61e4f00138
8 files changed
+41
-7
No files matched your search
@@ -231,6 +231,11 @@ pub struct Session {
|
||||
/// The system is in a low-memory episode (the cache budgets stay reduced until it ends, see
|
||||
/// [`sysinfo::SysMemory::still_low`] and [`Session::memory_budget`]).
|
||||
pub memory_low: bool,
|
||||
/// The most the footage frames (and decoded planes) hold by themselves, below the common
|
||||
/// budget ([`Session::apply_cache_budgets`]); `None`: the whole budget, as in the desktop app.
|
||||
/// Headless sessions (the CLI, its MCP server) set it: their renders read each footage frame
|
||||
/// about once, so frames kept up to the whole budget only cost memory (#4157).
|
||||
pub footage_cap: Option<usize>,
|
||||
/// The keyframe drag in progress (`keys.move` with a merge key).
|
||||
pub key_move: Option<KeyMove>,
|
||||
/// Reads the system's memory in the background for [`Session::memory_tick`].
|
||||
@@ -394,6 +399,7 @@ impl Default for Session {
|
||||
script_ui: scriptui::ScriptUi::default(),
|
||||
sys_memory: None,
|
||||
memory_low: false,
|
||||
footage_cap: None,
|
||||
key_move: None,
|
||||
memory_watch: Default::default(),
|
||||
disk_watch: Default::default(),
|
||||
|
||||
@@ -28,8 +28,8 @@ pub use choices::{APPEARANCE_MODES, DARK_THEMES, LANGUAGES, LIGHT_THEMES, THEMES
|
||||
pub use dialog::{Item, Kind, Page, pages, pages_json, todo_keys};
|
||||
pub use document::{migrate, page_id, section_key};
|
||||
pub use queries::{
|
||||
CacheCaps, FALLBACK_MEMORY_BUDGET, MEMORY_HEADROOM_PERCENT, MIN_MEMORY_BUDGET, MemoryBudget, PROCESS_PURGE_PERCENT, WEB_LAYER_CACHE, WEB_MEDIA_CACHE,
|
||||
WEB_MEMORY_BUDGET, WEB_PREVIEW_CACHE, mask_color,
|
||||
CacheCaps, FALLBACK_MEMORY_BUDGET, HEADLESS_MEDIA_CACHE, MEMORY_HEADROOM_PERCENT, MIN_MEMORY_BUDGET, MemoryBudget, PROCESS_PURGE_PERCENT, WEB_LAYER_CACHE,
|
||||
WEB_MEDIA_CACHE, WEB_MEMORY_BUDGET, WEB_PREVIEW_CACHE, mask_color,
|
||||
};
|
||||
pub use recent::{MAX_RECENT_SCRIPTS, RecentScript};
|
||||
pub use sections::{
|
||||
|
||||
@@ -172,6 +172,11 @@ pub const WEB_LAYER_CACHE: u64 = 512 << 20;
|
||||
/// The most the footage frame cache holds in the browser (see [`WEB_LAYER_CACHE`]).
|
||||
pub const WEB_MEDIA_CACHE: u64 = 256 << 20;
|
||||
|
||||
/// The most the footage frame cache holds in a headless session ([`crate::Session::footage_cap`],
|
||||
/// #4157): an export reads each frame about once, so this keeps only what a frame's layers share
|
||||
/// and what time effects read again (the footage cache's default size before the common budget).
|
||||
pub const HEADLESS_MEDIA_CACHE: u64 = 1 << 30;
|
||||
|
||||
/// Above this part (percent) of the installed RAM left after **RAM Reserved for Other
|
||||
/// Applications**, the process's measured memory makes the caches give way even within their
|
||||
/// budget ([`Prefs::process_limits`]): above the caches' budget plus most of the room left for
|
||||
|
||||
@@ -112,12 +112,13 @@ impl Session {
|
||||
/// (the layer cache, the footage frames and decoded planes, the preview frames), kept by the
|
||||
/// memory accountant, which frees the least valuable data first whichever cache holds it. No
|
||||
/// cache has a limit of its own below that budget, except the browser's caps
|
||||
/// ([`crate::prefs::MemoryBudget::caps`]; frontends apply the preview frames' cap).
|
||||
/// ([`crate::prefs::MemoryBudget::caps`]; frontends apply the preview frames' cap) and a
|
||||
/// headless session's footage cap ([`Session::footage_cap`]).
|
||||
pub fn apply_cache_budgets(&mut self) {
|
||||
let b = self.memory_budget();
|
||||
let caps = b.caps(cfg!(target_arch = "wasm32"));
|
||||
self.layer_cache.set_budget(caps.layer);
|
||||
self.footage.set_cache_budget(caps.footage);
|
||||
self.footage.set_cache_budget(self.footage_cap.map_or(caps.footage, |cap| cap.min(caps.footage)));
|
||||
let accountant = effectcraft_render::memory::Accountant::global();
|
||||
let layers: std::sync::Arc<dyn effectcraft_render::memory::MemoryHolder> = self.layer_cache.clone();
|
||||
accountant.register(&layers);
|
||||
|
||||
@@ -130,8 +130,13 @@ pub fn session() -> Session {
|
||||
/// as in the desktop app instead of the budget for unknown RAM. The desktop app reads it in the
|
||||
/// background every few seconds instead (`Session::memory_tick`); this waits for the reading
|
||||
/// (about a second on Windows). A session that can't read it keeps the budget for unknown RAM.
|
||||
/// Its footage frames keep at most [`effectcraft_engine::prefs::HEADLESS_MEDIA_CACHE`] (#4157): a
|
||||
/// render reads each frame about once, and frames kept up to the whole budget ran a render under
|
||||
/// a container's memory limit out of memory.
|
||||
pub fn headless_session() -> Session {
|
||||
let mut s = session();
|
||||
s.footage_cap = Some(usize::try_from(effectcraft_engine::prefs::HEADLESS_MEDIA_CACHE).unwrap_or(usize::MAX));
|
||||
s.apply_cache_budgets();
|
||||
s.take_memory_reading(effectcraft_engine::sysinfo::memory());
|
||||
s
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
//!
|
||||
//! #3941: a headless session (the CLI, its MCP server) reads the system's memory once, so its
|
||||
//! caches share the budget of the installed RAM, as in the desktop app.
|
||||
//!
|
||||
//! #4157: but a headless session's footage frames keep less than that budget: its renders read
|
||||
//! each frame about once, and frames kept up to the budget ran a render out of memory.
|
||||
|
||||
use effectcraft_engine::render::memory::Accountant;
|
||||
|
||||
@@ -22,10 +25,22 @@ fn a_host_session_bounds_the_caches() {
|
||||
eprintln!("the system's memory can't be read here: the headless reading is not checked");
|
||||
return;
|
||||
};
|
||||
let headless = effectcraft_host::headless_session();
|
||||
let mut headless = effectcraft_host::headless_session();
|
||||
let b = headless.memory_budget();
|
||||
assert_eq!(b.installed, Some(memory.total), "the budget of the installed RAM, not of unknown RAM");
|
||||
assert_eq!(b, effectcraft_engine::prefs::Prefs::default().memory_budget(Some(memory), b.reduced));
|
||||
assert_eq!(headless.layer_cache.budget(), b.bytes, "the caches follow it");
|
||||
assert_eq!(headless.export_cache_budget(), b.bytes, "exports and Render Queue runs follow it");
|
||||
|
||||
// #4157: the footage frames keep at most HEADLESS_MEDIA_CACHE (or the budget, if smaller),
|
||||
// also once the budget changes (a new memory reading, then the settings)
|
||||
let footage_capped = |s: &effectcraft_engine::Session, when: &str| {
|
||||
let budget = s.memory_budget().bytes;
|
||||
let cap = usize::try_from(effectcraft_engine::prefs::HEADLESS_MEDIA_CACHE).unwrap();
|
||||
assert_eq!(s.footage.cache_budget(), Some(cap.min(budget)), "{when}: the footage frames' cap under a {budget}-byte budget");
|
||||
};
|
||||
headless.take_memory_reading(Some(effectcraft_engine::sysinfo::SysMemory { total: 64 << 30, available: 48 << 30 }));
|
||||
footage_capped(&headless, "a new memory reading");
|
||||
headless.execute("prefs.set", serde_json::json!({"key": "memory.ramReservedGb", "value": 8})).unwrap();
|
||||
footage_capped(&headless, "a settings change");
|
||||
}
|
||||
@@ -18,7 +18,8 @@
|
||||
//! - Kept by the memory accountant (#3298): least recently used offered first, each entry worth
|
||||
//! what decoding it took. Also bounded by bytes by itself ([`CACHE_BUDGET`] until the caches'
|
||||
//! budget is set, then the footage frames' cap, [`set_budget`]: the whole budget on the
|
||||
//! desktop, at most [`crate::exr_channels::WEB_CACHE_CAP`] in the browser); there the newest
|
||||
//! desktop, less in a headless session (the CLI, #4157), at most
|
||||
//! [`crate::exr_channels::WEB_CACHE_CAP`] in the browser); there the newest
|
||||
//! entry stays even when it alone is over. Entries in use (planes an effect holds, a decode in
|
||||
//! progress, the last pictures' planes kept for their effects, [`HELD_FILES`]) are never
|
||||
//! dropped, by either.
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
//! frames, the decoded footage planes, the preview frames and the disk cache's write queue
|
||||
//! register here as [`MemoryHolder`]s and share one budget ([`Accountant::set_budget`], from
|
||||
//! Settings ▸ Memory & CPU ▸ RAM Reserved for Other Applications). No holder has a share of its
|
||||
//! own: when they hold more than the budget together, the accountant frees the least valuable
|
||||
//! own (some have a cap below it: the browser's caches, a headless session's footage frames,
|
||||
//! #4157): when they hold more than the budget together, the accountant frees the least valuable
|
||||
//! item first, whichever holder keeps it, in large steps: down to [`TRIM_TO`] of the budget, so
|
||||
//! a cache doesn't fill up and trim again with every insert.
|
||||
//!
|
||||
|
||||
Reference in new issue
Block a user