mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
perf(bench): split command and refresh time; refresh like the app; stop rows timing setup
perf_scenarios rows that time a command and then the canvas refresh now also record each part (cmd_samples_ms, refresh_samples_ms; samples_ms stays their sum, so budgets and the baseline are unaffected), the refresh kinds (gpu-rect, gpu-full, rect/full on the CPU compositor, none) and the CpuReason kind of any fallback. The console line ends with the medians (Summary::of's p50, as p50_ms uses). Bench::refresh follows the app's damage_since: it tracks the (document, revision) the canvas shows and redraws nothing at the same revision, the last edit's rect one revision on, else everything; drag_frame invalidates it. A timed refresh that also drew untimed setup edits, or redrew everything because the canvas showed nothing or another document, is reported on stderr. Rows that timed setup: - P8-P11 (duplicate/paste a 12 MP layer): the fresh layer and the copied clipboard are refreshed before the timer; the "first" rows delete what each sample added, so the stack no longer grows by two 12 MP layers per sample; the repeat rows get their own source and clipboard, warm up first, and are set up only when --only/--group selects them - Spot Healing 10 MP refreshes before its timer, so sample 1 no longer redraws the new document and the Content-Aware Fill row's edits - Open PSD drops the previous sample's session before the timer and frees its GPU textures and compositor pages (GpuCanvas::retain, as closing a document does); gpu_bytes 293 -> 112 MB Ported from perf/fix-measurement, which is too far behind main to merge; its xtask baseline merge, regressions_fail setting, 40-sample rows and nightly workflow change are left out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
2df9f80770
commit
5314c8e11b
2 files changed
+247
-66
No files matched your search
@@ -12,6 +12,11 @@
|
||||
//! its numbers are only comparable with other `--quick` runs. Every row records p50 / p95 / max
|
||||
//! over its samples, the peak resident memory measured in-process while it ran, and the GPU
|
||||
//! bytes the canvas holds for the document (texture + compositor) when there is a GPU.
|
||||
//!
|
||||
//! A row whose samples time a command and then the canvas refresh after it also records each
|
||||
//! part on its own (`cmd_samples_ms`, `refresh_samples_ms`; `samples_ms` stays their sum) and
|
||||
//! what the refreshes did (`refresh_kinds`: `Refresh::kind` counts, also "rect" / "full" without
|
||||
//! an adapter; `fallbacks`: `CpuReason::kind` of any refresh the wgpu compositor didn't draw).
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
@@ -21,7 +26,7 @@ use photocraft_color::{ColorMode, PixelFormat, SampleType};
|
||||
use photocraft_engine::Session;
|
||||
use photocraft_geom::Rect;
|
||||
use photocraft_raster::Surface;
|
||||
use photocraft_testkit::perf::{RssSampler, report, row, write_report};
|
||||
use photocraft_testkit::perf::{RssSampler, Summary, report, row, write_report};
|
||||
use photocraft_ui_egui::gpu_canvas::GpuCanvas;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
@@ -106,6 +111,45 @@ struct Bench {
|
||||
last_px: std::cell::Cell<u64>,
|
||||
/// Refreshed pixels per sample, for rows that report them (#9329); `record` prints the p50.
|
||||
px: std::cell::RefCell<Vec<u64>>,
|
||||
/// What the last `refresh` did: `Refresh::kind` and the `CpuReason::kind` of its fallback.
|
||||
last_kind: std::cell::Cell<(&'static str, Option<&'static str>)>,
|
||||
/// The current sample's command / refresh split, set by `after_cmd` or `drag_frame`.
|
||||
split: std::cell::Cell<Option<Split>>,
|
||||
/// The (document id, revision) the canvas shows, as the app's canvas cache keeps it; `None`
|
||||
/// when unknown (nothing refreshed yet, or a drag frame showed a document not in the session).
|
||||
shown: std::cell::Cell<Option<(u64, u64)>>,
|
||||
/// Revisions before the last edit that the last `refresh` also had to show (0 in the app's
|
||||
/// one-edit-per-frame case; 1 when the canvas didn't show this document at all): setup work
|
||||
/// that no untimed refresh caught up on.
|
||||
last_missed: std::cell::Cell<u64>,
|
||||
}
|
||||
|
||||
/// One sample's command time and the canvas refresh after it.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct Split {
|
||||
cmd_ms: f64,
|
||||
refresh_ms: f64,
|
||||
kind: &'static str,
|
||||
fallback: Option<&'static str>,
|
||||
/// See `Bench::last_missed`.
|
||||
missed: u64,
|
||||
}
|
||||
|
||||
/// The p50 of `v` as the row's `p50_ms` takes it.
|
||||
fn median(v: &[f64]) -> f64 {
|
||||
Summary::of(v).map_or(f64::NAN, |s| s.p50)
|
||||
}
|
||||
|
||||
/// A GPU refresh's kind and fallback; `refresh_with` reports nothing to draw as `"rect"` (like
|
||||
/// the CPU-compositor rect upload), which the bench calls `"none"` as its CPU path does.
|
||||
fn gpu_kind(r: &photocraft_ui_egui::gpu_canvas::Refresh) -> (&'static str, Option<&'static str>) {
|
||||
let fallback = r.fallback.as_ref().map(|f| f.kind());
|
||||
(if r.kind == "rect" && r.px == 0 && fallback.is_none() { "none" } else { r.kind }, fallback)
|
||||
}
|
||||
|
||||
/// The layer a command's result names (`{"layer": id}`), else the active layer it left.
|
||||
fn added(s: &Session, result: &Value) -> Res<u64> {
|
||||
result.get("layer").and_then(Value::as_u64).map_or_else(|| active_layer(s), Ok)
|
||||
}
|
||||
|
||||
impl Bench {
|
||||
@@ -113,9 +157,8 @@ impl Bench {
|
||||
self.only.as_ref().is_none_or(|o| name.contains(o.as_str()))
|
||||
}
|
||||
|
||||
/// The canvas refresh after an edit (`canvas::ensure_gpu`): the damage rect grown by the
|
||||
/// effect reach when the session reports one, else everything; waits for the GPU.
|
||||
/// Re-composite only `r` of the active document (what the canvas hadn't shown yet).
|
||||
/// Re-composite only `r` of the active document: the caller knows the canvas already shows
|
||||
/// the rest of the current revision (a stroke's live preview, say).
|
||||
fn refresh_rect(&self, s: &Session, r: photocraft_geom::Rect) -> Res<f64> {
|
||||
let st = s.active().ok_or("no document")?;
|
||||
let doc = &st.doc;
|
||||
@@ -132,22 +175,53 @@ impl Bench {
|
||||
}
|
||||
}
|
||||
}
|
||||
self.shown.set(Some((doc.id.0, st.revision)));
|
||||
Ok(ms(t))
|
||||
}
|
||||
|
||||
/// The canvas refresh after an edit (`canvas::ensure_gpu`), with the damage the app's
|
||||
/// `damage_since` gives it: nothing when the canvas shows this revision, the last edit's rect
|
||||
/// grown by the effect reach when it showed the one before (and the session reports a rect),
|
||||
/// else everything (`full`, or several edits since the last refresh); waits for the GPU.
|
||||
fn refresh(&self, s: &Session, full: bool) -> Res<f64> {
|
||||
let st = s.active().ok_or("no document")?;
|
||||
let doc = &st.doc;
|
||||
let damage = if full { None } else { st.last_damage.map(|r| r.inflate(reach(&doc.layers)).intersect(&doc.bounds())) };
|
||||
// The revision of this document the canvas showed; `None` when it showed nothing or
|
||||
// another document (a new one, a drag frame's, the previous group's).
|
||||
let showed = self.shown.replace(Some((doc.id.0, st.revision))).filter(|&(id, _)| id == doc.id.0).map(|(_, rev)| rev);
|
||||
let seen = showed.filter(|_| !full);
|
||||
// Redrawing everything only because the canvas didn't show this document also draws
|
||||
// its setup: count that as missed unless the row asked for a full refresh.
|
||||
self.last_missed.set(match showed {
|
||||
_ if full => 0,
|
||||
Some(rev) => st.revision.saturating_sub(rev).saturating_sub(1),
|
||||
None => 1,
|
||||
});
|
||||
let damage = match seen {
|
||||
Some(rev) if rev == st.revision => Some(Rect::EMPTY),
|
||||
Some(rev) if rev.checked_add(1) == Some(st.revision) => st.last_damage.map(|r| r.inflate(reach(&doc.layers)).intersect(&doc.bounds())),
|
||||
_ => None,
|
||||
};
|
||||
let t = Instant::now();
|
||||
match &self.gpu {
|
||||
Some((g, rs)) => {
|
||||
self.last_px.set(g.refresh(doc.id.0, doc, damage, None).px);
|
||||
let r = g.refresh(doc.id.0, doc, damage, None);
|
||||
self.last_px.set(r.px);
|
||||
self.last_kind.set(gpu_kind(&r));
|
||||
let _ = rs.device.poll(eframe::wgpu::PollType::Wait { submission_index: None, timeout: None });
|
||||
}
|
||||
None => {
|
||||
let r = damage.unwrap_or(doc.bounds()).intersect(&doc.bounds());
|
||||
self.last_px.set(if r.is_empty() { 0 } else { r.size().area() });
|
||||
// The kinds `GpuCanvas::refresh` gives the CPU compositor's rect and full draws.
|
||||
let kind = if r.is_empty() {
|
||||
"none"
|
||||
} else if damage.is_some() {
|
||||
"rect"
|
||||
} else {
|
||||
"full"
|
||||
};
|
||||
self.last_kind.set((kind, None));
|
||||
if !r.is_empty() {
|
||||
std::hint::black_box(photocraft_compose::render(doc, r));
|
||||
}
|
||||
@@ -156,6 +230,17 @@ impl Bench {
|
||||
Ok(ms(t))
|
||||
}
|
||||
|
||||
/// The time of a command `t` started timing plus the canvas refresh after it (`full`: the
|
||||
/// whole document), with the split kept for this sample's `cmd_samples_ms` /
|
||||
/// `refresh_samples_ms`.
|
||||
fn after_cmd(&self, s: &Session, t: Instant, full: bool) -> Res<f64> {
|
||||
let cmd_ms = ms(t);
|
||||
let refresh_ms = self.refresh(s, full)?;
|
||||
let (kind, fallback) = self.last_kind.get();
|
||||
self.split.set(Some(Split { cmd_ms, refresh_ms, kind, fallback, missed: self.last_missed.get() }));
|
||||
Ok(cmd_ms + refresh_ms)
|
||||
}
|
||||
|
||||
/// Frame `i` of a Move tool drag of `layer` (#128): the canvas shows the document with the
|
||||
/// layer at the pointer (`layer_multi_cmds::moved`) and recomposites where it was in the
|
||||
/// previous frame and where it is now (`move_ui::damage`).
|
||||
@@ -169,16 +254,35 @@ impl Bench {
|
||||
let t = Instant::now();
|
||||
let shown = photocraft_engine::layer_multi_cmds::moved(&doc, &[id], d, d / 2).map_err(|e| e.to_string())?;
|
||||
let damage = was.translate(prev, prev / 2).union(&was.translate(d, d / 2)).inflate(1).intersect(&doc.bounds());
|
||||
match &self.gpu {
|
||||
let cmd_ms = ms(t);
|
||||
let t = Instant::now();
|
||||
// The canvas now shows a document the session doesn't hold: the next refresh redraws all.
|
||||
self.shown.set(None);
|
||||
let kind = match &self.gpu {
|
||||
Some((g, rs)) => {
|
||||
g.refresh(doc.id.0, &shown, Some(damage), None);
|
||||
let r = g.refresh(doc.id.0, &shown, Some(damage), None);
|
||||
let _ = rs.device.poll(eframe::wgpu::PollType::Wait { submission_index: None, timeout: None });
|
||||
gpu_kind(&r)
|
||||
}
|
||||
None => {
|
||||
std::hint::black_box(photocraft_compose::render(&shown, damage));
|
||||
(if damage.is_empty() { "none" } else { "rect" }, None)
|
||||
}
|
||||
};
|
||||
let refresh_ms = ms(t);
|
||||
self.split.set(Some(Split { cmd_ms, refresh_ms, kind: kind.0, fallback: kind.1, missed: 0 }));
|
||||
Ok(cmd_ms + refresh_ms)
|
||||
}
|
||||
|
||||
/// Frees the canvas's textures and compositor pages of documents not in `live`, as the app
|
||||
/// does when a document closes (`GpuCanvas::retain`).
|
||||
fn retain(&self, live: &[u64]) {
|
||||
if let Some((g, _)) = &self.gpu {
|
||||
g.retain(live);
|
||||
}
|
||||
if self.shown.get().is_some_and(|(id, _)| !live.contains(&id)) {
|
||||
self.shown.set(None);
|
||||
}
|
||||
Ok(ms(t))
|
||||
}
|
||||
|
||||
fn gpu_bytes(&self, s: &Session) -> Option<u64> {
|
||||
@@ -197,6 +301,7 @@ impl Bench {
|
||||
self.sampler.reset();
|
||||
self.px.borrow_mut().clear();
|
||||
let mut samples = Vec::new();
|
||||
let mut splits = Vec::new();
|
||||
let mut run = || -> Res<()> {
|
||||
if warm {
|
||||
f(self, s, 0)?;
|
||||
@@ -204,20 +309,47 @@ impl Bench {
|
||||
self.px.borrow_mut().clear();
|
||||
}
|
||||
for i in 0..reps.max(1) {
|
||||
self.split.set(None);
|
||||
samples.push(f(self, s, i + 1)?);
|
||||
splits.push(self.split.take());
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
let result = run();
|
||||
self.record(name, s, &samples, result);
|
||||
let splits: Option<Vec<Split>> = splits.into_iter().collect();
|
||||
self.record(name, s, &samples, splits.as_deref().unwrap_or_default(), result);
|
||||
}
|
||||
|
||||
fn record(&mut self, name: &str, s: &Session, samples: &[f64], result: Res<()>) {
|
||||
/// Reports a row. `splits` (one per sample, or none) adds the command / refresh split.
|
||||
fn record(&mut self, name: &str, s: &Session, samples: &[f64], splits: &[Split], result: Res<()>) {
|
||||
match result {
|
||||
Ok(()) => {
|
||||
let r = row(name, samples, self.sampler.peak(), self.gpu_bytes(s));
|
||||
let mut r = row(name, samples, self.sampler.peak(), self.gpu_bytes(s));
|
||||
let mut split = String::new();
|
||||
if !splits.is_empty() && splits.len() == samples.len() {
|
||||
let cmd: Vec<f64> = splits.iter().map(|x| x.cmd_ms).collect();
|
||||
let refresh: Vec<f64> = splits.iter().map(|x| x.refresh_ms).collect();
|
||||
let mut kinds = std::collections::BTreeMap::<&str, usize>::new();
|
||||
let mut fallbacks = std::collections::BTreeSet::<&str>::new();
|
||||
for x in splits {
|
||||
*kinds.entry(x.kind).or_default() += 1;
|
||||
fallbacks.extend(x.fallback);
|
||||
}
|
||||
split = format!(" cmd {:.2} + refresh {:.2} ms {kinds:?}", median(&cmd), median(&refresh));
|
||||
// A timed refresh that also drew earlier, untimed edits overstates this row.
|
||||
let missed = splits.iter().filter(|x| x.missed > 0).count();
|
||||
if missed > 0 {
|
||||
eprintln!("{name}: {missed} of {} timed refreshes also redrew setup edits no untimed refresh showed", splits.len());
|
||||
}
|
||||
if let Some(o) = r.as_object_mut() {
|
||||
o.insert("cmd_samples_ms".into(), json!(cmd));
|
||||
o.insert("refresh_samples_ms".into(), json!(refresh));
|
||||
o.insert("refresh_kinds".into(), json!(kinds));
|
||||
o.insert("fallbacks".into(), json!(fallbacks));
|
||||
}
|
||||
}
|
||||
println!(
|
||||
"{name:<52} p50 {:>9.2} ms p95 {:>9.2} ms max {:>9.2} ms (n {}, peak RSS {} MB)",
|
||||
"{name:<52} p50 {:>9.2} ms p95 {:>9.2} ms max {:>9.2} ms (n {}, peak RSS {} MB){split}",
|
||||
r["p50_ms"].as_f64().unwrap_or(f64::NAN),
|
||||
r["p95_ms"].as_f64().unwrap_or(f64::NAN),
|
||||
r["max_ms"].as_f64().unwrap_or(f64::NAN),
|
||||
@@ -383,6 +515,10 @@ fn main() {
|
||||
current: None,
|
||||
last_px: std::cell::Cell::new(0),
|
||||
px: std::cell::RefCell::new(Vec::new()),
|
||||
last_kind: std::cell::Cell::new(("none", None)),
|
||||
split: std::cell::Cell::new(None),
|
||||
shown: std::cell::Cell::new(None),
|
||||
last_missed: std::cell::Cell::new(0),
|
||||
};
|
||||
println!("perf_scenarios: {} mode, {} reps, {}", if quick { "quick" } else { "full" }, reps, adapter.as_deref().unwrap_or("CPU canvas"));
|
||||
let t_all = Instant::now();
|
||||
@@ -464,28 +600,28 @@ fn layered_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
let d = if i % 2 == 0 { 10 } else { -10 };
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.translate", json!({"layer": target, "dx": d, "dy": d / 2}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
b.time("move tool drag frame, styled layer", &mut s, reps, true, |b, s, i| b.drag_frame(s, target, i));
|
||||
b.time("set layer opacity + refresh", &mut s, reps, true, |b, s, i| {
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.setProps", json!({"layer": target, "opacity": if i % 2 == 0 { 0.6 } else { 0.9 }}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
b.time("set layer fill + refresh", &mut s, reps, true, |b, s, i| {
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.setProps", json!({"layer": target, "fill": if i % 2 == 0 { 0.5 } else { 1.0 }}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
b.time("set blend mode + refresh", &mut s, reps, true, |b, s, i| {
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.setProps", json!({"layer": target, "blend": if i % 2 == 0 { "Multiply" } else { "Normal" }}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
b.time("toggle visibility + refresh", &mut s, reps, true, |b, s, i| {
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.setProps", json!({"layer": target, "visible": i % 2 == 0}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
let _ = exec(&mut s, "layer.setProps", json!({"layer": target, "visible": true}));
|
||||
b.time("undo move + refresh", &mut s, reps, true, |b, s, _| {
|
||||
@@ -493,7 +629,7 @@ fn layered_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
b.refresh(s, false)?;
|
||||
let t = Instant::now();
|
||||
exec(s, "edit.undo", json!({}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
b.time("redo opacity change + refresh", &mut s, reps, true, |b, s, i| {
|
||||
exec(s, "layer.setProps", json!({"layer": target, "opacity": 0.5 + 0.02 * i as f64}))?;
|
||||
@@ -501,7 +637,7 @@ fn layered_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
b.refresh(s, false)?;
|
||||
let t = Instant::now();
|
||||
exec(s, "edit.redo", json!({}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
|
||||
// Advanced Blending on one layer sends the whole document to the CPU compositor (#6689):
|
||||
@@ -514,7 +650,7 @@ fn layered_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
b.time("set opacity on a layer with Advanced Blending + refresh", &mut s, reps, true, |b, s, i| {
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.setProps", json!({"layer": target, "opacity": if i % 2 == 0 { 0.6 } else { 0.9 }}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
let _ = exec(&mut s, "layer.layerStyle.blendingOptions", json!({"layer": other, "knockout": "none"}));
|
||||
let _ = b.refresh(&s, true);
|
||||
@@ -527,7 +663,7 @@ fn layered_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
b.time("toggle adjustment layer visibility + refresh", &mut s, reps, true, |b, s, i| {
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.setProps", json!({"layer": adj, "visible": i % 2 == 1}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
let _ = exec(&mut s, "layer.setProps", json!({"layer": adj, "visible": true}));
|
||||
let _ = exec(&mut s, "layer.select", json!({"layer": target}));
|
||||
@@ -557,48 +693,75 @@ fn layered_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
Err(e) => b.errors.push(("full-canvas styled layer".into(), e)),
|
||||
}
|
||||
|
||||
// A 12 MP layer, duplicated and pasted: the first time (a fresh layer, cold caches) and
|
||||
// again (the same source).
|
||||
// A 12 MP layer, duplicated and pasted: the first time (a fresh layer, so the copy's caches
|
||||
// are cold) and again (the same source). The fresh layer is on screen before the timer
|
||||
// starts, as in the app (its setup is several edits, so that untimed refresh redraws
|
||||
// everything).
|
||||
// Each "first" sample deletes the layers it added (untimed), so every sample lands on the
|
||||
// same stack instead of one two 12 MP layers taller each time.
|
||||
let (lw, lh) = sz.big_layer;
|
||||
let fresh_layer = |s: &mut Session| -> Res<u64> {
|
||||
let (lx, ly) = ((w - lw) / 2, (h - lh) / 2);
|
||||
let fresh_layer = |b: &Bench, s: &mut Session| -> Res<u64> {
|
||||
exec(s, "layer.new.layer", json!({"name": "12 MP"}))?;
|
||||
exec(s, "select.rect", json!({"x": (w - lw) / 2, "y": (h - lh) / 2, "width": lw, "height": lh}))?;
|
||||
exec(s, "select.rect", json!({"x": lx, "y": ly, "width": lw, "height": lh}))?;
|
||||
exec(s, "edit.fill", json!({"color": "#3070a0"}))?;
|
||||
exec(s, "select.deselect", json!({}))?;
|
||||
b.refresh(s, false)?;
|
||||
active_layer(s)
|
||||
};
|
||||
let reps_big = reps.min(5);
|
||||
let mut src = 0;
|
||||
b.time("duplicate 12 MP layer (first) + refresh", &mut s, reps_big, false, |b, s, _| {
|
||||
src = fresh_layer(s)?;
|
||||
b.refresh(s, false)?;
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.duplicate", json!({"layer": src}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
});
|
||||
b.time("duplicate 12 MP layer (repeat) + refresh", &mut s, reps_big, false, |b, s, _| {
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.duplicate", json!({"layer": src}))?;
|
||||
let v = ms(t) + b.refresh(s, false)?;
|
||||
exec(s, "edit.undo", json!({}))?;
|
||||
b.refresh(s, false)?;
|
||||
Ok(v)
|
||||
});
|
||||
b.time("paste 12 MP layer (first) + refresh", &mut s, reps_big, false, |b, s, _| {
|
||||
let id = fresh_layer(s)?;
|
||||
let delete_layers = |b: &Bench, s: &mut Session, ids: &[u64]| -> Res<()> {
|
||||
for &id in ids {
|
||||
exec(s, "layer.delete", json!({"layer": id}))?;
|
||||
}
|
||||
b.refresh(s, false).map(|_| ())
|
||||
};
|
||||
let copy_layer = |b: &Bench, s: &mut Session, id: u64| -> Res<()> {
|
||||
exec(s, "layer.select", json!({"layer": id}))?;
|
||||
exec(s, "select.all", json!({}))?;
|
||||
exec(s, "edit.copy", json!({}))?;
|
||||
exec(s, "select.deselect", json!({}))?;
|
||||
b.refresh(s, false)?;
|
||||
b.refresh(s, false).map(|_| ())
|
||||
};
|
||||
let reps_big = reps.min(5);
|
||||
b.time("duplicate 12 MP layer (first) + refresh", &mut s, reps_big, false, |b, s, _| {
|
||||
let src = fresh_layer(b, s)?;
|
||||
let t = Instant::now();
|
||||
exec(s, "edit.paste", json!({}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
let copy = exec(s, "layer.duplicate", json!({"layer": src}))?;
|
||||
let v = b.after_cmd(s, t, false)?;
|
||||
delete_layers(b, s, &[added(s, ©)?, src])?;
|
||||
Ok(v)
|
||||
});
|
||||
b.time("paste 12 MP layer (repeat) + refresh", &mut s, reps_big, false, |b, s, _| {
|
||||
b.time("paste 12 MP layer (first) + refresh", &mut s, reps_big, false, |b, s, _| {
|
||||
let src = fresh_layer(b, s)?;
|
||||
copy_layer(b, s, src)?;
|
||||
let t = Instant::now();
|
||||
let pasted = exec(s, "edit.paste", json!({}))?;
|
||||
let v = b.after_cmd(s, t, false)?;
|
||||
delete_layers(b, s, &[added(s, &pasted)?, src])?;
|
||||
Ok(v)
|
||||
});
|
||||
|
||||
// The source the repeat rows duplicate and paste (copied once), only when they run.
|
||||
let repeat_rows = ["duplicate 12 MP layer (repeat) + refresh", "paste 12 MP layer (repeat) + refresh"];
|
||||
if !repeat_rows.iter().any(|r| b.wanted(r)) {
|
||||
return;
|
||||
}
|
||||
let src = match fresh_layer(b, &mut s).and_then(|id| copy_layer(b, &mut s, id).map(|()| id)) {
|
||||
Ok(id) => id,
|
||||
Err(e) => return b.errors.push(("12 MP source layer".into(), e)),
|
||||
};
|
||||
b.time("duplicate 12 MP layer (repeat) + refresh", &mut s, reps_big, true, |b, s, _| {
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.duplicate", json!({"layer": src}))?;
|
||||
let v = b.after_cmd(s, t, false)?;
|
||||
exec(s, "edit.undo", json!({}))?;
|
||||
b.refresh(s, false)?;
|
||||
Ok(v)
|
||||
});
|
||||
b.time("paste 12 MP layer (repeat) + refresh", &mut s, reps_big, true, |b, s, _| {
|
||||
let t = Instant::now();
|
||||
exec(s, "edit.paste", json!({}))?;
|
||||
let v = ms(t) + b.refresh(s, false)?;
|
||||
let v = b.after_cmd(s, t, false)?;
|
||||
exec(s, "edit.undo", json!({}))?;
|
||||
b.refresh(s, false)?;
|
||||
Ok(v)
|
||||
@@ -655,12 +818,12 @@ fn full_canvas_layer_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
b.time(opacity, &mut s, reps, true, |b, s, i| {
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.setProps", json!({"layer": mid, "opacity": if i % 2 == 0 { 0.5 } else { 1.0 }}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
b.time(hide, &mut s, reps, true, |b, s, i| {
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.setProps", json!({"layer": mid, "visible": i % 2 == 1}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
// #6533: an adjustment among them, added after the rows above so their document is unchanged.
|
||||
// It lands on top (above the active `full n-1`), #6533's "hide the top adjustment layer" case.
|
||||
@@ -682,7 +845,7 @@ fn full_canvas_layer_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
b.refresh(s, false)?;
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.setProps", json!({"layer": adj, "visible": false}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
}
|
||||
Err(e) => b.errors.push((adjust.to_string(), e)),
|
||||
@@ -752,13 +915,13 @@ fn many_layer_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
b.time(&name, &mut s, reps, true, |b, s, i| {
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.translate", json!({"layer": mid, "dx": if i % 2 == 0 { 1 } else { -1 }, "dy": 0}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
// Layer › New › Layer: as fast at any layer count. Undone (untimed) so the count stays put.
|
||||
b.time(new_layer, &mut s, reps, true, |b, s, _| {
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.new.layer", json!({}))?;
|
||||
let took = ms(t) + b.refresh(s, false)?;
|
||||
let took = b.after_cmd(s, t, false)?;
|
||||
exec(s, "edit.undo", json!({}))?;
|
||||
b.refresh(s, false)?;
|
||||
Ok(took)
|
||||
@@ -803,12 +966,12 @@ fn depth_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
let (x, y) = (200 + (i as u32 * 97) % (w - 400), 200 + (i as u32 * 61) % (h - 400));
|
||||
let t = Instant::now();
|
||||
exec(s, "paint.stroke", json!({"points": [[x, y]], "size": 60, "hardness": 0.8, "color": "#c03020"}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
b.time(&mv, &mut s, reps, true, |b, s, i| {
|
||||
let t = Instant::now();
|
||||
exec(s, "layer.translate", json!({"layer": layer, "dx": if i % 2 == 0 { 10 } else { -10 }, "dy": 0}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -826,12 +989,18 @@ fn job_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
Ok(psd) => {
|
||||
let mut holder = Session::new();
|
||||
b.time(open, &mut holder, reps, true, |b, s, _| {
|
||||
// Close the previous sample's document before the timer, on the GPU too (each
|
||||
// import has a new id, so its pages would otherwise stay resident): its
|
||||
// teardown isn't decode.
|
||||
drop(std::mem::replace(s, Session::new()));
|
||||
b.retain(&[]);
|
||||
let t = Instant::now();
|
||||
let d = photocraft_io::import("layered.psd", &psd).map_err(|e| e.to_string())?.document;
|
||||
*s = Session::new();
|
||||
s.open_document(d, Some("layered.psd".into()));
|
||||
Ok(ms(t) + b.refresh(s, true)?)
|
||||
b.after_cmd(s, t, true)
|
||||
});
|
||||
drop(holder);
|
||||
b.retain(&[]);
|
||||
}
|
||||
Err(e) => b.errors.push((open.into(), e)),
|
||||
}
|
||||
@@ -851,12 +1020,14 @@ fn job_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
exec(s, "select.deselect", json!({}))?;
|
||||
Ok(v)
|
||||
});
|
||||
// The canvas shows this document (and the fill's undone edits) before the timer.
|
||||
let _ = b.refresh(&s, true);
|
||||
b.time(heal, &mut s, reps, false, |b, s, i| {
|
||||
let (x, y) = (w / 4 + i as u32 * 60, h / 4);
|
||||
let pts: Vec<Value> = (0..10).map(|k| json!([x + k * 12, y + k * 4])).collect();
|
||||
let t = Instant::now();
|
||||
exec(s, "paint.spotHealing", json!({"points": pts, "size": 60}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
}
|
||||
Err(e) => b.errors.push((caf.into(), e)),
|
||||
@@ -1031,7 +1202,7 @@ fn full_refresh_frame_scenario(b: &mut Bench, name: &str, w: u32, h: u32) {
|
||||
Ok(())
|
||||
})();
|
||||
let st = std::mem::take(&mut harness.state_mut().session);
|
||||
b.record(name, &st, &samples, run);
|
||||
b.record(name, &st, &samples, &[], run);
|
||||
}
|
||||
|
||||
/// The whole app (kittest harness, CPU canvas) with a 24 MP document: frame times while a
|
||||
@@ -1074,7 +1245,7 @@ fn frame_scenario(b: &mut Bench, name: &str, w: u32, h: u32) {
|
||||
})();
|
||||
// The rows' document handle: the harness's session.
|
||||
let st = std::mem::take(&mut harness.state_mut().session);
|
||||
b.record(name, &st, &samples, run);
|
||||
b.record(name, &st, &samples, &[], run);
|
||||
}
|
||||
|
||||
/// #211 rows: selection algorithms, Content-Aware Scale and Select Subject on 24 MP, and a brush
|
||||
@@ -1138,7 +1309,7 @@ fn algorithm_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
let (x, y) = (200 + (i as u32 * 97) % (w - 400), 200 + (i as u32 * 61) % (h - 400));
|
||||
let t = Instant::now();
|
||||
exec(s, "paint.stroke", json!({"points": [[x, y]], "size": 40, "hardness": 0.8, "color": "#c03020"}))?;
|
||||
Ok(ms(t) + b.refresh(s, false)?)
|
||||
b.after_cmd(s, t, false)
|
||||
});
|
||||
}
|
||||
// P32: releasing a long stroke. The canvas draws it live (untimed here); the release offers
|
||||
@@ -1277,7 +1448,7 @@ fn liquify_preview_scenario(b: &mut Bench) {
|
||||
if let Some(median) = low_sorted.get(low_sorted.len() / 2) {
|
||||
println!(" existing 1600 px proxy update p50 {median:.2} ms (lower-resolution output)");
|
||||
}
|
||||
b.record(name, &Session::new(), &samples, Ok(()));
|
||||
b.record(name, &Session::new(), &samples, &[], Ok(()));
|
||||
}
|
||||
|
||||
/// The share of the canvas `r` covers.
|
||||
@@ -1326,7 +1497,7 @@ fn redraw_area_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
let before = s.active().ok_or("no document")?.doc.clone();
|
||||
let t = Instant::now();
|
||||
exec(s, "edit.undo", json!({}))?;
|
||||
let took = ms(t) + b.refresh(s, false)?;
|
||||
let took = b.after_cmd(s, t, false)?;
|
||||
b.px.borrow_mut().push(b.last_px.get());
|
||||
let after = s.active().ok_or("no document")?.doc.clone();
|
||||
if photocraft_engine::layer_multi_cmds::step_damage(&before, &after).is_some_and(|r| r.is_empty()) {
|
||||
@@ -1363,7 +1534,7 @@ fn redraw_area_scenarios(b: &mut Bench, sz: &Sizes) {
|
||||
let before = s.active().ok_or("no document")?.doc.clone();
|
||||
let t = Instant::now();
|
||||
exec(s, "edit.fill", json!({"color": color}))?;
|
||||
let took = ms(t) + b.refresh(s, false)?;
|
||||
let took = b.after_cmd(s, t, false)?;
|
||||
b.px.borrow_mut().push(b.last_px.get());
|
||||
let after = s.active().ok_or("no document")?.doc.clone();
|
||||
if photocraft_engine::layer_multi_cmds::step_damage(&before, &after).is_some_and(|r| r.is_empty()) {
|
||||
|
||||
@@ -506,6 +506,16 @@ want the verdict, the merged `results.json`/`summary.md` and the regression chec
|
||||
Every `--bench` name must match a `[[bench]]` name in `perf/budgets.toml`; an unknown name
|
||||
is rejected before any benchmark runs or any report or baseline is written.
|
||||
|
||||
`perf_scenarios` rows that time a command and then the canvas refresh after it also split each
|
||||
sample: `cmd_samples_ms` and `refresh_samples_ms` (`samples_ms`, what budgets judge, is their sum),
|
||||
`refresh_kinds` (how many refreshes were `gpu-rect`, `gpu-full`, `rect`/`full` on the CPU
|
||||
compositor, also without an adapter, `none` when nothing needed drawing, …) and `fallbacks` (why
|
||||
the wgpu compositor didn't draw, `CpuReason::kind`). The console line ends with the medians, e.g.
|
||||
`cmd 0.06 + refresh 1.71 ms {"gpu-rect": 7}`, so a slow row says whether the engine or the canvas
|
||||
is the cost before you profile it. The bench refreshes like the app's `damage_since`: the last
|
||||
edit's rect only when the canvas showed the revision before it, else everything; a row whose timed
|
||||
refresh also had to draw untimed setup edits is reported on stderr.
|
||||
|
||||
Read the sample count before quoting a percentile. `--reps` defaults to 7 in `--quick` and 15
|
||||
otherwise, it is per bench, and some rows cap it themselves (the `#211` algorithm rows use
|
||||
`b.reps.min(5)`); percentiles are nearest-rank, so **at n ≤ 5 the "p95" is simply the maximum**. A
|
||||
|
||||
Reference in new issue
Block a user