bug: the canvas limit is 128 MP, but rendering one needs about 4 GB #9
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#9
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. Measured peak RSS.
Steps to reproduce
opendither big.png --render out.pngWhat should have happened
A document either fits in memory — and then it renders — or it is refused with a message, like a canvas that is too large already is.
What happened instead
Measured peak RSS for a single
--renderof a plain PNG:That is a marginal cost of about 31 MB per megapixel, and it is what the pipeline inherently holds: the composited RGBA frame, the
[f32; 3]working bufferengine::processbuilds (12 bytes per pixel), a clone of it for error diffusion, the packed RGBA result and the output.MAX_CANVAS_PIXELSallows 128 MP (app/src/layers.rs:22,canvas_fits), so a document the app accepts needs roughly 4 GB to render — on a machine that cannot provide it the process is killed by the OOM killer instead of being told no.The layer stack has no budget at all: every layer keeps a full RGBA image for its lifetime,
fn add_layer(main.rs:971) stores the whole composite as a new layer, andduplicate_layercopies it again. Ten layers on a 24 MP canvas is 1 GB of pixels before anything renders.Suggested fix
MAX_CANVAS_PIXELSbecomes something likebudget_bytes / 31 MB per MPwith a documented factor and a comment pointing at the measurement (the repository already works this way elsewhere). Keep the existing refusal message, so nothing else has to change.sum(layer pixels) + composite + buffers <= budget, checked when a layer is added or duplicated, with a status-line refusal instead of a kill.[f32; 3]working buffer is the one worth removing: the tone stage is a 256-entry LUT on bytes and the spatial filters could work in a tiledf32window with a band halo.A check that would catch it
--auditcan assert the arithmetic (peak_estimate_pixels * 31 MBagainst the budget constant) and that a canvas one pixel above the derived limit is refused. A test that only refuses one specific number will be wrong again the next time a buffer is added, so the estimate and the buffers should be derived from the same named constants.