Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

perf(doc): share the XMP packet, Duotone PSD data and unsupported adjustment bytes between snapshots

Finn Newick0351f635d795
diff --git a/crates/doc/src/adjust.rs b/crates/doc/src/adjust.rs
index 855cd1f39..e197236a4 100644
--- a/crates/doc/src/adjust.rs
+++ b/crates/doc/src/adjust.rs
@@ -281,10 +281,11 @@ pub enum Adjustment {
relative: bool,
adjustments: [[f32; 4]; 9],
},
- /// A PSD adjustment we can't evaluate yet; preserved raw for round-trip.
+ /// A PSD adjustment we can't evaluate yet; preserved raw for round-trip, shared between
+ /// document snapshots (#4535).
Unsupported {
psd_key: String,
- raw: Vec<u8>,
+ raw: std::sync::Arc<[u8]>,
},
}
diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs
index c4f7f523d..88a092537 100644
--- a/crates/doc/src/lib.rs
+++ b/crates/doc/src/lib.rs
@@ -841,7 +841,10 @@ pub type PsdGlobalBlock = ([u8; 4], [u8; 4], Arc<Vec<u8>>);
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Metadata {
- pub xmp: Option<String>,
+ /// The XMP packet as stored, kept as text so properties PhotoCraft doesn't model survive.
+ /// Shared like the other payloads here: cloning a document or a history state never copies
+ /// it (#4535).
+ pub xmp: Option<Arc<str>>,
pub exif: Option<Arc<Vec<u8>>>,
/// Free-form image text (PNG tEXt/zTXt/iTXt, TIFF ASCII tags), including duplicate keys.
pub text: Vec<(String, String)>,
diff --git a/crates/doc/src/mode.rs b/crates/doc/src/mode.rs
index 96e129cbe..263cb83df 100644
--- a/crates/doc/src/mode.rs
+++ b/crates/doc/src/mode.rs
@@ -57,8 +57,9 @@ impl DuotoneInk {
pub struct Duotone {
pub inks: Vec<DuotoneInk>,
/// The PSD colour-mode data this came from, written back unchanged while the inks are unedited.
+ /// Shared between document snapshots (#4535).
#[serde(default)]
- pub psd_raw: Option<Vec<u8>>,
+ pub psd_raw: Option<std::sync::Arc<[u8]>>,
}
impl DuotoneInk {
diff --git a/crates/engine/src/file_cmds.rs b/crates/engine/src/file_cmds.rs
index 43828b76b..4bdf30e28 100644
--- a/crates/engine/src/file_cmds.rs
+++ b/crates/engine/src/file_cmds.rs
@@ -850,7 +850,7 @@ fn file_info(s: &mut Session, p: &Value) -> Result<Value> {
let xmp = s.active().ok_or(EngineError::NoDocument)?.doc.metadata.xmp.clone();
let new = write_file_info(xmp.as_deref(), p);
s.edit("File Info", |doc, _| {
- doc.metadata.xmp = Some(new);
+ doc.metadata.xmp = Some(new.into());
Ok(())
})?;
}
diff --git a/crates/engine/src/file_cmds/tests.rs b/crates/engine/src/file_cmds/tests.rs
index 3cc72c30c..3a3a5b9d9 100644
--- a/crates/engine/src/file_cmds/tests.rs
+++ b/crates/engine/src/file_cmds/tests.rs
@@ -505,7 +505,7 @@ fn file_info_translations_survive_undo_and_psd_round_trip() {
for depth in [8, 16, 32] {
let mut s = session(8, 8, depth);
s.edit("Set metadata", |doc, _| {
- doc.metadata.xmp = Some(MULTILINGUAL_XMP.to_string());
+ doc.metadata.xmp = Some(MULTILINGUAL_XMP.into());
Ok(())
})
.unwrap();
@@ -515,7 +515,7 @@ fn file_info_translations_survive_undo_and_psd_round_trip() {
assert!(s.undo());
assert_eq!(doc(&s).metadata.xmp.as_deref(), Some(MULTILINGUAL_XMP));
assert!(s.redo());
- assert_eq!(doc(&s).metadata.xmp.as_deref(), Some(edited.as_str()));
+ assert_eq!(doc(&s).metadata.xmp.as_deref(), Some(&*edited));
let (bytes, _) = encode(doc(&s), "x.psd", None).unwrap();
let back = photocraft_io::import("x.psd", &bytes).unwrap().document;
assert_translations_kept(back.metadata.xmp.as_deref().unwrap());
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index 04063d307..f9ef4ee39 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -1580,3 +1580,37 @@ fn merge_down_on_a_group_merges_the_group() {
s.execute("edit.undo", json!({})).unwrap();
assert!(s.active().unwrap().doc.layer(photocraft_doc::LayerId(group)).is_some());
}
+
+/// #4535: every edit snapshots the document into history. The large payloads it carries (the
+/// XMP packet, Duotone's PSD data, an unsupported adjustment's bytes) are shared between the
+/// snapshot and the document, not copied per state.
+#[test]
+fn history_states_share_large_document_payloads() {
+ use photocraft_doc::{Adjustment, Duotone, DuotoneInk, Layer, LayerContent};
+ let mut s = Session::new();
+ s.execute("file.new", json!({"width": 16, "height": 16})).unwrap();
+ let raw_id = {
+ let st = s.active_mut().unwrap();
+ let doc = std::sync::Arc::make_mut(&mut st.doc);
+ doc.metadata.xmp = Some("x".repeat(1 << 20).into());
+ doc.duotone = Some(Duotone { inks: vec![DuotoneInk::new("Black", [0.0; 3])], psd_raw: Some(vec![7u8; 1 << 16].into()) });
+ let layer = Layer::new("kept", LayerContent::Adjustment(Adjustment::Unsupported { psd_key: "abcd".into(), raw: vec![9u8; 1 << 16].into() }));
+ let id = layer.id;
+ doc.layers.push(layer);
+ id
+ };
+ s.execute("layer.new.layer", json!({})).unwrap();
+ let st = s.active().unwrap();
+ let before = st.history.state(st.history.past_len() - 1).unwrap();
+ let (now, then) = (&st.doc, &before);
+ assert!(!std::sync::Arc::ptr_eq(now, then), "the edit made a new document");
+ let xmp = |d: &Document| d.metadata.xmp.clone().unwrap();
+ assert!(std::sync::Arc::ptr_eq(&xmp(now), &xmp(then)), "the XMP packet is shared");
+ let duotone = |d: &Document| d.duotone.as_ref().and_then(|d| d.psd_raw.clone()).unwrap();
+ assert!(std::sync::Arc::ptr_eq(&duotone(now), &duotone(then)), "the Duotone data is shared");
+ let raw = |d: &Document| match &d.layer(raw_id).unwrap().content {
+ LayerContent::Adjustment(Adjustment::Unsupported { raw, .. }) => raw.clone(),
+ other => panic!("{other:?}"),
+ };
+ assert!(std::sync::Arc::ptr_eq(&raw(now), &raw(then)), "the adjustment's bytes are shared");
+}
diff --git a/crates/format/src/convert.rs b/crates/format/src/convert.rs
index 51d6183ba..878e6445b 100644
--- a/crates/format/src/convert.rs
+++ b/crates/format/src/convert.rs
@@ -233,7 +233,7 @@ pub(crate) fn doc_m(d: &Document, sink: &mut dyn Sink) -> DocM {
ruler_origin: d.ruler_origin,
selection: d.selection.as_ref().map(|s| surface_m(s, sink)),
metadata: MetadataM {
- xmp: d.metadata.xmp.clone(),
+ xmp: d.metadata.xmp.as_deref().map(str::to_owned),
exif: opt_blob(&d.metadata.exif, sink),
text: d.metadata.text.clone(),
psd_resources: d.metadata.psd_resources.iter().map(|(id, n, b)| (*id, n.clone(), sink.blob(b))).collect(),
@@ -575,7 +575,7 @@ impl Loader<'_> {
}
let quick_mask = m.quick_mask.as_ref().map(|c| self.channel(c)).transpose()?;
let mut md = Metadata {
- xmp: m.metadata.xmp.clone(),
+ xmp: m.metadata.xmp.as_deref().map(std::sync::Arc::from),
exif: self.opt_blob(&m.metadata.exif)?,
text: m.metadata.text.clone(),
psd_resources: Vec::new(),
diff --git a/crates/format/tests/common/mod.rs b/crates/format/tests/common/mod.rs
index 8d5641d9c..9f2662e6a 100644
--- a/crates/format/tests/common/mod.rs
+++ b/crates/format/tests/common/mod.rs
@@ -226,7 +226,7 @@ pub fn rich_doc(mode: ColorMode, depth: SampleType) -> Document {
d.color_table = Some(photocraft_doc::ColorTable { colors: vec![[0, 0, 0], [255, 128, 0]], transparent: Some(1) });
d.duotone = Some(photocraft_doc::Duotone {
inks: vec![photocraft_doc::DuotoneInk::new("Black", [0.0; 3]), photocraft_doc::DuotoneInk::new("PANTONE 151 C", [1.0, 0.5, 0.0])],
- psd_raw: Some(vec![1, 2, 3]),
+ psd_raw: Some(vec![1, 2, 3].into()),
});
d.guides =
Guides { horizontal: vec![10.0, 20.5], vertical: vec![100.25], colors: vec![GuideColor { vertical: true, position: 100.25, rgb: [0x33, 0x66, 0xff] }] };
diff --git a/crates/io/src/adjust_map.rs b/crates/io/src/adjust_map.rs
index d4bc31269..2ada62a5f 100644
--- a/crates/io/src/adjust_map.rs
+++ b/crates/io/src/adjust_map.rs
@@ -29,7 +29,7 @@ fn bef32(d: &[u8], at: usize) -> Option<f32> {
}
fn unsupported(key: &[u8; 4], data: &[u8]) -> Adjustment {
- Adjustment::Unsupported { psd_key: String::from_utf8_lossy(key).into_owned(), raw: data.to_vec() }
+ Adjustment::Unsupported { psd_key: String::from_utf8_lossy(key).into_owned(), raw: data.into() }
}
fn levels_rec(d: &[u8], at: usize) -> Option<LevelsChannel> {
@@ -787,7 +787,7 @@ pub fn write(adj: &Adjustment) -> Vec<([u8; 4], Vec<u8>)> {
Adjustment::Unsupported { psd_key, raw } => {
let k = psd_key.as_bytes();
if k.len() == 4 {
- return vec![([k[0], k[1], k[2], k[3]], raw.clone())];
+ return vec![([k[0], k[1], k[2], k[3]], raw.to_vec())];
}
}
}
@@ -990,7 +990,7 @@ mod tests {
let inkl = Adjustment::Levels { master: lc(0, 255), per_channel: [lc(0, 255), lc(5, 250), lc(0, 255)], space: ToneSpace::Cmyk, black: lc(30, 255) };
let b = write(&inkl);
assert_eq!(parse(&b[0].0, &b[0].1, None, Channels::Cmyk), inkl);
- rt(Adjustment::Unsupported { psd_key: "selc".into(), raw: vec![1, 2, 3] });
+ rt(Adjustment::Unsupported { psd_key: "selc".into(), raw: vec![1, 2, 3].into() });
rt(Adjustment::GradientMap { stops: vec![(0.0, [0.0, 0.0, 0.0]), (0.5, [1.0, 0.0, 0.0]), (1.0, [1.0, 1.0, 1.0])], reverse: true, dither: false });
rt(Adjustment::GradientMap { stops: vec![(0.0, [0.0, 0.0, 0.0]), (1.0, [1.0, 1.0, 1.0])], reverse: false, dither: true });
rt(Adjustment::SelectiveColor { relative: true, adjustments: std::array::from_fn(|r| [r as f32 * 10.0 - 40.0, 5.0, -100.0, 100.0]) });
@@ -1304,7 +1304,7 @@ mod tests {
assert_eq!(*t, photocraft_cms::lutfile::LutFile::identity(2).data);
}
// Every kind except a malformed Unsupported key has an encoding.
- assert!(write(&Adjustment::Unsupported { psd_key: "abc".into(), raw: vec![] }).is_empty());
+ assert!(write(&Adjustment::Unsupported { psd_key: "abc".into(), raw: Vec::new().into() }).is_empty());
}
#[test]
diff --git a/crates/io/src/flat.rs b/crates/io/src/flat.rs
index 54fe96090..ee2e2487f 100644
--- a/crates/io/src/flat.rs
+++ b/crates/io/src/flat.rs
@@ -234,7 +234,7 @@ pub(crate) fn image_to_document(name: &str, img: &Image) -> Result<ImportResult,
doc.layers.push(layer);
doc.icc_profile = img.icc.clone().map(Arc::new);
doc.metadata.exif = img.meta.exif.clone().map(Arc::new);
- doc.metadata.xmp = img.meta.xmp.clone();
+ doc.metadata.xmp = img.meta.xmp.as_deref().map(Arc::from);
doc.metadata.text = img.meta.text.clone();
if let Some((x, y)) = img.meta.dpi {
doc.resolution_dpi = x;
@@ -453,7 +453,7 @@ fn document_to_image_for(doc: &Document, warnings: &mut Vec<String>, cmyk_target
};
let meta = codecs::Metadata {
exif: doc.metadata.exif.as_ref().map(|e| e.to_vec()),
- xmp: doc.metadata.xmp.clone(),
+ xmp: doc.metadata.xmp.as_deref().map(str::to_owned),
text: doc.metadata.text.clone(),
dpi: Some((doc.resolution_dpi, doc.resolution_dpi)),
..Default::default()
diff --git a/crates/io/src/psd_export.rs b/crates/io/src/psd_export.rs
index 47861dbcc..5427460a4 100644
--- a/crates/io/src/psd_export.rs
+++ b/crates/io/src/psd_export.rs
@@ -1451,7 +1451,7 @@ pub(crate) fn estimate_psd_size(doc: &Document) -> Option<u64> {
structural_bytes = structural_bytes
.checked_add(u64::try_from(doc.icc_profile.as_ref().map_or(0, |profile| profile.len())).ok()?)?
- .checked_add(u64::try_from(doc.metadata.xmp.as_ref().map_or(0, String::len)).ok()?)?
+ .checked_add(u64::try_from(doc.metadata.xmp.as_deref().map_or(0, str::len)).ok()?)?
.checked_add(u64::try_from(doc.metadata.exif.as_ref().map_or(0, |data| data.len())).ok()?)?;
for (_, name, data) in &doc.metadata.psd_resources {
structural_bytes = structural_bytes.checked_add(u64::try_from(name.len()).ok()?)?.checked_add(u64::try_from(data.len()).ok()?)?;
diff --git a/crates/io/src/psd_import.rs b/crates/io/src/psd_import.rs
index 94c4ea993..d91784396 100644
--- a/crates/io/src/psd_import.rs
+++ b/crates/io/src/psd_import.rs
@@ -761,7 +761,7 @@ pub fn psd_to_document_with(file: &PsdFile, ctl: &photocraft_raster::Interrupt)
}
}
ids::ICC_PROFILE => doc.icc_profile = Some(Arc::new(r.data.clone())),
- ids::XMP => doc.metadata.xmp = Some(String::from_utf8_lossy(&r.data).into_owned()),
+ ids::XMP => doc.metadata.xmp = Some(String::from_utf8_lossy(&r.data).into()),
ids::EXIF => doc.metadata.exif = Some(Arc::new(r.data.clone())),
1032 => parse_guides(&r.data, &mut doc),
ids::GLOBAL_ANGLE | ids::GLOBAL_ALTITUDE => {
@@ -959,8 +959,10 @@ pub fn psd_to_document_with(file: &PsdFile, ctl: &photocraft_raster::Interrupt)
doc.color_table = Some(photocraft_doc::ColorTable { colors, transparent: None });
} else if h.color_mode == PsdMode::Duotone && !file.color_mode_data.is_empty() {
// The duotone ink block is undocumented: keep it raw; the image shows as its gray plate.
- doc.duotone =
- Some(photocraft_doc::Duotone { inks: vec![photocraft_doc::DuotoneInk::new("Black", [0.0; 3])], psd_raw: Some(file.color_mode_data.clone()) });
+ doc.duotone = Some(photocraft_doc::Duotone {
+ inks: vec![photocraft_doc::DuotoneInk::new("Black", [0.0; 3])],
+ psd_raw: Some(file.color_mode_data.as_slice().into()),
+ });
cx.warn("duotone inks are not interpreted (shown as grayscale)");
} else if !file.color_mode_data.is_empty() {
cx.warn("color mode data is not preserved");
diff --git a/crates/io/src/tiff_layers.rs b/crates/io/src/tiff_layers.rs
index 8a5810e92..3afc0b59d 100644
--- a/crates/io/src/tiff_layers.rs
+++ b/crates/io/src/tiff_layers.rs
@@ -240,7 +240,7 @@ pub(crate) fn export_layered(doc: &Document, opts: &ExportOptions, ctl: &photocr
// importer reads it back from there unchanged. A second copy in `meta.exif` (the codec's
// Exif directory) would be read back in its place, rebuilt without the thumbnail and IFD0
// orientation (#1545).
- xmp: doc.metadata.xmp.clone().filter(|_| opts.xmp == crate::XmpEmbed::All),
+ xmp: doc.metadata.xmp.as_deref().map(str::to_owned).filter(|_| opts.xmp == crate::XmpEmbed::All),
text: if opts.xmp == crate::XmpEmbed::All { doc.metadata.text.clone() } else { Vec::new() },
dpi: Some((doc.resolution_dpi, doc.resolution_dpi)),
photoshop_resources: Some(resources),
diff --git a/crates/io/tests/adjust_blend_roundtrip.rs b/crates/io/tests/adjust_blend_roundtrip.rs
index 4e8b727af..fee2c01f8 100644
--- a/crates/io/tests/adjust_blend_roundtrip.rs
+++ b/crates/io/tests/adjust_blend_roundtrip.rs
@@ -101,7 +101,7 @@ fn adjustments() -> Vec<(Adjustment, bool)> {
(Adjustment::SelectiveColor { relative: true, adjustments: std::array::from_fn(|r| [r as f32 * 10.0 - 40.0, 5.0, -30.0, 20.0]) }, true),
(Adjustment::SelectiveColor { relative: false, adjustments: std::array::from_fn(|r| [0.0, r as f32 * 5.0, 0.0, -10.0]) }, true),
// A block this version cannot read (a truncated Selective Color) is kept verbatim.
- (Adjustment::Unsupported { psd_key: "selc".into(), raw: vec![0, 1, 0, 0] }, true),
+ (Adjustment::Unsupported { psd_key: "selc".into(), raw: vec![0, 1, 0, 0].into() }, true),
];
// Compile-time guard: a new Adjustment kind must be added to the list above.
for (a, _) in &all {
diff --git a/crates/io/tests/adjust_warnings.rs b/crates/io/tests/adjust_warnings.rs
index 9b91f40bc..617911f18 100644
--- a/crates/io/tests/adjust_warnings.rs
+++ b/crates/io/tests/adjust_warnings.rs
@@ -17,7 +17,7 @@ fn reopen(adj: Adjustment, path: &str, opts: &ExportOptions) -> (Document, Vec<S
#[test]
fn unreadable_adjustments_warn_on_open() {
// A Color Lookup that uses a profile, not a LUT file: kept verbatim, not applied.
- let profile = Adjustment::Unsupported { psd_key: "clrL".into(), raw: vec![0, 2, 0, 0] };
+ let profile = Adjustment::Unsupported { psd_key: "clrL".into(), raw: vec![0, 2, 0, 0].into() };
for (path, opts) in [("x.psd", ExportOptions::default()), ("x.psb", ExportOptions { force_psb: true, ..Default::default() })] {
let (doc, warnings) = reopen(profile.clone(), path, &opts);
assert!(matches!(&doc.layers[0].content, LayerContent::Adjustment(Adjustment::Unsupported { .. })), "{path}");
@@ -26,7 +26,7 @@ fn unreadable_adjustments_warn_on_open() {
assert!(w[0].contains("Color Lookup") && w[0].contains("version 2") && w[0].contains("no effect"), "{path}: {}", w[0]);
}
// Another kind without a specific reason still names the layer and the adjustment.
- let (_, warnings) = reopen(Adjustment::Unsupported { psd_key: "levl".into(), raw: vec![0, 9] }, "x.psd", &ExportOptions::default());
+ let (_, warnings) = reopen(Adjustment::Unsupported { psd_key: "levl".into(), raw: vec![0, 9].into() }, "x.psd", &ExportOptions::default());
assert!(warnings.iter().any(|w| w.contains("Teal Look") && w.contains("Levels settings could not be read;")), "{warnings:?}");
}
diff --git a/crates/io/tests/color.rs b/crates/io/tests/color.rs
index c5d447990..a1d4a5bd3 100644
--- a/crates/io/tests/color.rs
+++ b/crates/io/tests/color.rs
@@ -234,7 +234,7 @@ fn gradient_maps_with_cmyk_lab_gray_stops_import_and_keep_their_space() {
}
let fmt = doc.pixel_format();
doc.layers.push(raster("Background", fmt, doc.bounds(), 3, false));
- doc.layers.push(Layer::new("Map", LayerContent::Adjustment(Adjustment::Unsupported { psd_key: "grdm".into(), raw: block.clone() })));
+ doc.layers.push(Layer::new("Map", LayerContent::Adjustment(Adjustment::Unsupported { psd_key: "grdm".into(), raw: block.as_slice().into() })));
let bytes = export(&doc, "x.psd", &ExportOptions::default()).unwrap().bytes;
let mut back = import("x.psd", &bytes).unwrap().document;
let LayerContent::Adjustment(Adjustment::GradientMap { stops: got, .. }) = &back.layers[1].content else {
diff --git a/crates/io/tests/common/mod.rs b/crates/io/tests/common/mod.rs
index 28c1a0190..c964b08b8 100644
--- a/crates/io/tests/common/mod.rs
+++ b/crates/io/tests/common/mod.rs
@@ -172,7 +172,7 @@ pub fn gen_doc(mode: ColorMode, depth: SampleType, f: Features) -> Document {
black: Vec::new(),
pencil: false,
},
- Adjustment::Unsupported { psd_key: "selc".into(), raw: vec![0, 1, 0, 0] },
+ Adjustment::Unsupported { psd_key: "selc".into(), raw: vec![0, 1, 0, 0].into() },
];
// Colour adjustments (Photoshop offers them for colour documents only: they would tint
// a grayscale composite).
diff --git a/crates/io/tests/psd_structure.rs b/crates/io/tests/psd_structure.rs
index 5627dca3f..643e6ad54 100644
--- a/crates/io/tests/psd_structure.rs
+++ b/crates/io/tests/psd_structure.rs
@@ -361,9 +361,7 @@ fn adjustment_and_fill_layers_from_psd() {
use photocraft_doc::{Adjustment, Fill};
assert!(matches!(d.layers[n - 4].content, LayerContent::Adjustment(Adjustment::Invert)));
assert!(matches!(d.layers[n - 3].content, LayerContent::Adjustment(Adjustment::Posterize { levels: 4 })));
- assert!(
- matches!(&d.layers[n - 2].content, LayerContent::Adjustment(Adjustment::Unsupported { psd_key, raw }) if psd_key == "selc" && raw == &vec![1, 2, 3])
- );
+ assert!(matches!(&d.layers[n - 2].content, LayerContent::Adjustment(Adjustment::Unsupported { psd_key, raw }) if psd_key == "selc" && **raw == [1, 2, 3]));
assert!(matches!(&d.layers[n - 1].content, LayerContent::Fill(Fill::Solid(c)) if c.c[0] == 1.0));
}
diff --git a/crates/io/tests/xmp_export.rs b/crates/io/tests/xmp_export.rs
index 8d22017ff..08af0006c 100644
--- a/crates/io/tests/xmp_export.rs
+++ b/crates/io/tests/xmp_export.rs
@@ -17,7 +17,7 @@ fn doc_with_xmp() -> Document {
let mut s = Surface::new(d.pixel_format());
s.fill_rect(photocraft_geom::Rect::new(0, 0, 8, 6), &[0.5, 0.4, 0.3, 1.0]);
d.layers.push(Layer::new("flat", LayerContent::Raster(s)));
- d.metadata.xmp = Some(XMP.to_string());
+ d.metadata.xmp = Some(XMP.into());
d
}
diff --git a/docs/architecture.md b/docs/architecture.md
index 67eebe9cc..975a0b6e8 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -1,6 +1,6 @@
# PhotoCraft architecture
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-13 · **Change:** minor (workspace size and test counts recounted; current-state summary added; the design plan below is kept, with its deviations listed) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-14 · **Change:** minor (large payloads in the document model are `Arc`-shared, #4535; earlier: workspace size and test counts recounted; current-state summary added; the design plan below is kept, with its deviations listed) · **Target:** Adobe Photoshop 2026
## Current state (2026-10-10)
@@ -53,7 +53,7 @@ This plan sets out:
2. **Everything is a command.** Each user-visible action has a stable `CommandId` (such as `filter.blur.gaussianBlur`) with typed, serializable parameters. The menu, command palette, shortcuts, recorded actions/macros, CLI, MCP and plugins all dispatch the same commands.
3. **Data describes the UI; toolkits draw it.** Tools produce *overlay primitives* (lines, handles, marching-ants paths) as data. Filter and adjustment dialogs are generated from *parameter schemas*. A new toolkit implements one renderer for each, not about 150 bespoke dialogs.
4. **One algorithm, one parameter struct.** Every algorithm has a CPU reference implementation (Rust + rayon, deterministic). Some also get a GPU implementation (WGSL). Both read the same `#[repr(C)]` `bytemuck::Pod` parameter struct. We never keep hand-synced copies of an algorithm in several languages.
-5. **Immutable snapshots, copy-on-write tiles.** Pixel data is stored in `Arc`-shared 256² tiles. Taking a document snapshot is O(layers), which makes undo, background jobs, autosave and UI reads cheap and lock-free.
+5. **Immutable snapshots, copy-on-write tiles.** Pixel data is stored in `Arc`-shared 256² tiles. Taking a document snapshot is O(layers), which makes undo, background jobs, autosave and UI reads cheap and lock-free. Every other large payload in `photocraft-doc` is `Arc`-shared too (the XMP packet, EXIF, raw PSD resources and blocks, a layer's or Duotone's raw PSD data, an unsupported adjustment's bytes), so a snapshot never copies one; a new field that can hold a large payload follows the same rule (#4535).
6. **Determinism.** The same input gives the same output across CPU and GPU (within tolerance), across thread counts, and between preview and export. Noise is hashed from document coordinates.
7. **Pure Rust by default.** C/C++ dependencies are allowed only behind Cargo features, in I/O-edge crates (for example an optional LibRaw).
8. **Clean-room.** We study other editors' *behaviour* only, and we must **not copy proprietary source** (Rust, WGSL, C++ or JS), even where it ships as readable source. Specs come from public format docs (Adobe PSD spec, ISO/ICC), academic papers (PatchMatch, Poisson blending, ARAP) and observed behaviour. Never paste code from another product.
@@ -588,6 +588,7 @@ Each phase ends with a demoable build and green CI on all targets. Phases 8–10
| Date | Change | Summary |
|---|---|---|
+| 2026-10-14 | minor | Principle 5: every large payload in the document model is `Arc`-shared, so snapshots never copy one (#4535) |
| 2026-10-13 | minor | Workspace size and `#[test]` counts recounted (393k → 539k lines, 5,460 → 8,040 tests); other current-state figures unchanged |
| 2026-10-10 | minor | Current-state summary and deviations from the plan; status line; broken link to `photoshop-parity.md` repointed to `target-app-parity.md` |
| 2026-09-30 | major | Design plan v1 |