Phase 3b: bound resident raster pixels with an eviction LRU
Scrubbing a large paint project no longer accumulates every visited frame in RAM. A fault-in-recency LRU keeps the most-recently-paged-in RASTER_RESIDENT_MAX (12) keyframes resident and drops the pixels of older *clean* ones (re-arming their fault-in so they re-page on revisit). The shown frame is always the most-recent fault-in, so it's never evicted. Data-loss safety: a new `dirty` flag marks any keyframe whose `raw_pixels` were mutated by editing (stroke/fill/paint-bucket/floating-lift + their undo/redo) and is NOT yet in the container. Dirty keyframes are NEVER evicted — they're only unpinned from the LRU. The flag is cleared on a successful save, which also re-arms the LRU for the now-clean resident frames so the bound still applies to frames edited this session. Also: the save loop now walks all layers (incl. nested) to match the load path's recursive fault-in arming — evicted frames keep their existing container row (media_exists), and nested raster keyframes are persisted + covered by live_media. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
2e07a88905
commit
39dc402ba3
@@ -44,6 +44,7 @@ impl Action for RasterFillAction {
|
||||
let kf = raster.ensure_keyframe_at(self.time, self.width, self.height);
|
||||
kf.raw_pixels = self.buffer_after.clone();
|
||||
kf.texture_dirty = true;
|
||||
kf.dirty = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -57,6 +58,7 @@ impl Action for RasterFillAction {
|
||||
let kf = raster.ensure_keyframe_at(self.time, self.width, self.height);
|
||||
kf.raw_pixels = self.buffer_before.clone();
|
||||
kf.texture_dirty = true;
|
||||
kf.dirty = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ impl Action for RasterStrokeAction {
|
||||
let kf = get_keyframe_mut(document, &self.layer_id, self.time, self.width, self.height)?;
|
||||
kf.raw_pixels = self.buffer_after.clone();
|
||||
kf.texture_dirty = true;
|
||||
kf.dirty = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -57,6 +58,7 @@ impl Action for RasterStrokeAction {
|
||||
let kf = get_keyframe_mut(document, &self.layer_id, self.time, self.width, self.height)?;
|
||||
kf.raw_pixels = self.buffer_before.clone();
|
||||
kf.texture_dirty = true;
|
||||
kf.dirty = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -386,8 +386,11 @@ pub fn save_beam(
|
||||
// --- raster keyframes -> media rows (PNG), keyed by keyframe id ---
|
||||
// (Phase 0 writes all resident frames each save; a disk-dirty flag to skip
|
||||
// unchanged frames in place is deferred to Phase 3.)
|
||||
// Walk ALL layers (incl. nested in groups/clips) so nested raster keyframes
|
||||
// are persisted too, and so `live_media` covers them — matching the load path,
|
||||
// which arms `needs_fault_in` recursively. Top-level-only projects are unaffected.
|
||||
let mut raster_count = 0usize;
|
||||
for layer in &document.root.children {
|
||||
for layer in document.all_layers() {
|
||||
if let crate::layer::AnyLayer::Raster(rl) = layer {
|
||||
for kf in &rl.keyframes {
|
||||
if !kf.raw_pixels.is_empty() {
|
||||
|
||||
@@ -123,6 +123,13 @@ pub struct RasterKeyframe {
|
||||
/// set true on load and again when evicted. Never serialized.
|
||||
#[serde(skip)]
|
||||
pub needs_fault_in: bool,
|
||||
/// Phase 3a eviction: set `true` whenever user editing mutates `raw_pixels`
|
||||
/// (brush, fill, paint-bucket, floating-selection commit/lift, undo/redo of
|
||||
/// those). A dirty keyframe's current pixels are NOT yet persisted in the
|
||||
/// container, so it must NEVER be evicted (doing so would silently lose the
|
||||
/// unsaved edit). Cleared on a successful save. Never serialized.
|
||||
#[serde(skip)]
|
||||
pub dirty: bool,
|
||||
}
|
||||
|
||||
fn default_true() -> bool { true }
|
||||
@@ -147,6 +154,7 @@ impl RasterKeyframe {
|
||||
raw_pixels: Vec::new(),
|
||||
texture_dirty: true,
|
||||
needs_fault_in: false,
|
||||
dirty: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user