performance: the effect stack copies the whole picture for every effect #8
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
linux
packaging
performance
question
tech-debt
ui
windows
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ben/openDither#8
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Version: 0.1.2 (
main@41c7fc5)System: Linux, X11 (XWayland), 16 cores.
Steps to reproduce
opendither picture.pngwith a 4000×3000 picture.tint), then read the status line:rendered in … ms.What should have happened
Adding an effect costs the time of that effect, and the stack reuses buffers between effects.
What happened instead
app/src/fx.rs:533fn apply_atstarts with a full copy of the picture, and every effect then allocates another full picture for its own output:At 24 MP that is 96 MB per copy: a ten-effect stack allocates (and frees) about 1 GB per render, on top of the ~3 buffers
engine::processalready holds. The stack is also strictly sequential and single-threaded, while the dither, the tone stage and the composite next to it are now split over the cores (src/par.rs) — so with many effects the effect stack becomes the only thing running on one core.Two copies are avoidable without touching a single algorithm: the first effect can write into a buffer it is handed instead of cloning
src, and each effect can consume the buffer the previous one produced (ping-pong between two buffers) instead of allocating a newRgbaImageper step. Both keep the picture bit-identical.Suggested fix
apply_attakes an owned scratch buffer and ping-pongs: effect n reads buffer A, writes buffer B, swaps.par::rowsapplies, since each of them writes only its own rows.A check that would catch it
--timingonly measures the dither. A--timing --effectsrow that renders a 1200×900 picture with 1, 2, 4, 8 effects and prints the ms per effect would make a regression visible; the numbers per effect should stay flat as the stack grows.