Repository navigation
M5.6: a view slot renders one job at a time, so a drag's renders don't pile up - #1302
Conversation
…t pile up The job pool replaced a slot's queued job, but a newer job for a slot whose job was already running started beside it on another worker. A slider drag submits faster than renders finish, so one view had several renders on the GPU at once and about 30 % of finished renders were thrown away (61 MP raw, 1:1 Exposure drag). Now a slot's next job waits until its running one ends (a newer submission still replaces it in the queue); other slots are not held up, and a job that panics frees its slot. Measured on a 61 MP raw at 1:1, 8 s Exposure drags (M4 Max): thrown-away renders roughly halved, and frames over 20 ms 0 % in every one of 4 runs (one run of the overlapping pool dropped 10 %). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FredApps
left a comment
There was a problem hiding this comment.
Reviewed and tested at d7037d1 on Linux. cargo test -p lightcraft-preview passes, including the two new tests.
The fix looks right. Lock order is the same everywhere (queue, then busy, in both take and finished). The Free guard frees the slot during unwinding, so a panicking job doesn't leave its slot stuck, and run_pending uses the guard too.
Small notes, none of them blocking:
busyis only ever touched whilequeueis held, so it could live inside the queue mutex, e.g.Mutex<(Vec<Entry>, Vec<S>)>. That would remove the second lock and the "locked insidequeue" rule that only lives in a comment.finishedcallsnotify_allevery time a job ends. That's fine at this pool size;notify_onewould only be correct if a single waiter could always take the freed slot, so leaving it as is is reasonable.- It might help to add a line to the doc of
is_queued: a job for a busy slot now stays queued while the slot's job runs, so callers that readis_queuedas "about to start" see it as queued for longer.
Tests: cargo test -p lightcraft-preview passes (15/15).
|
One behaviour change to be aware of, measured while prototyping drag latency on a Sony ILCE-7RM6 (64 MP raws, RTX 4070 Ti SUPER, release build, a saturated 4-CPU quota, medians of 3). With one job per slot, the loupe's render of the next photo waits for the running render of the photo you just stepped past, because both are
We tried keeping the busy check per (slot, photo) for view slots ( |
|
Thanks @dev-null-undefined, that's a useful measurement. I approved this without considering that case: with one job per |
|
Landed on main in #1431. Thank you, @mattsivak! Generated by Claude Code |
Problem:
JobPool::submitreplaced a slot's queued job, but a newer job for a slot whose job was already running started beside it on another worker. A slider drag submits faster than renders finish, so one view (the loupe, its 1:1 zoom window) had several renders on the GPU at once, and about 30 % of finished renders were thrown away as superseded. Found while profiling #1228 with a per-frame display: in an 8 s 1:1 Exposure drag on a 61 MP raw, 194 of 645 and 248 of 719 finished renders were discarded.Fix (
crates/preview/src/pool.rs): the pool keeps the slots that have a job running (Shared::busy, locked inside the queue lock).takeskips queued jobs for a busy slot. A newer submission still replaces the queued one, so the slot runs the newest request next. A drop guard frees the slot when the job ends, also when it panics, and wakes the workers. Other slots aren't held up; thumbnails each have their own slot and are unaffected.Measured: release app, M4 Max,
arw-sony-a7cr-compressed.arw(61 MP) at 1:1, 8 s scripted Exposure drags (ui.dragWidget), frame intervals logged by the per-frame display. The runs are noisy on a working machine, but:Tests (
crates/preview/src/tests.rs):a_slot_runs_one_job_at_a_time: a second and third submission for a busy slot wait (the third replaces the second), another slot runs meanwhile, and the newest runs once the slot frees. The concurrency high-water mark is 1. Fails without the fix ("a second job of slot 1 started beside the first").a_panicking_job_frees_its_slot.cargo test -p lightcraft-preview: 15 pass.cargo test -p lightcraft-ui-egui: 738 pass, 7 fail onmainwithout this change too:tests_dialog_fit::export_dialog_is_unchanged_in_a_tall_window(known, see LR-VIEW-ZOOM: slider drags stay sharp where the GPU keeps up (#330) #1009) and 6tests_model_setuptests, which I re-ran with the pool change reverted and they fail the same.lightcraft-previewapart from the toolchain-1.99chunks_exact_to_as_chunkslint in untouched code (Issue #989: clippy 1.99, fill_box reads its buffer with as_chunks::<3>() (item 4) #997).Related: #1240 (renders as window textures, now opt-in), where the measurements behind this came from.
Refs #330 (slider drags too slow) and #1228.