Keep a clip as the box it covers, not as a value for every pixel of the page - #14
Merged
Conversation
tannevaled
force-pushed
the
bounded-clip
branch
from
August 27, 2026 08:11
adc1e9a to
a0f0cd7
Compare
tannevaled
force-pushed
the
annotations
branch
2 times, most recently
from
August 27, 2026 08:56
36d3904 to
88c6a18
Compare
…he page Narrowing the clip made a float for every pixel of the image, whatever the shape covered, and did it again for every narrowing. A page narrows its clip more often than one would think: a real French government form does it two thousand one hundred and forty times, and one arXiv figure six thousand seven hundred. Measured before this, drawing a single page: fr-cerfa/cerfa_11126.pdf 1 090 815 bytes 9 350 MB 16.9 s 2603.22026/Fig6New.pdf 566 578 bytes 218 762 MB 6.6 s A hundred and thirteen kilobytes of paper asking for two hundred and eighteen gigabytes is not a page anybody can draw twice at once. A clip is now the box it has narrowed itself down to and the coverage inside that box. Narrowing intersects the boxes first, so what is stored is never larger than the smaller of the two shapes, and a clip to a corner of the page costs a corner of the page. fr-cerfa/cerfa_11126.pdf 6 036 MB 6.8 s 2603.22026/Fig6New.pdf 719 MB 0.7 s Three hundred and four times less memory for the figure and nine times less time; the form is a third less and two and a half times faster, and what remains there is two thousand large clips that genuinely are large. Proved to change nothing: 3 040 corpus pages drawn before and after, every page's pixels hashed, every hash identical. I also tried keeping no coverage at all for a clip that lets everything through inside its box, which is what a clip to a rectangle ought to be. It never once fired on either of the files above — a rectangle's edge pixels are covered fractionally, so the grid is never all ones — so it is not here. An optimisation that does not fire is complexity with nothing to show for it. Found by the robustness campaign, which measured it across 33 393 render stages: median 34 MB, p99 5 618 MB, worst 97 333 MB.
tannevaled
force-pushed
the
bounded-clip
branch
from
August 27, 2026 08:58
a0f0cd7 to
307b75d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Narrowing the clip made a
float32for every pixel of the image, whatever the shape actually covered, and did it again for every narrowing. Pages narrow their clip far more often than one would guess: a real French government form does it 2 140 times, one arXiv figure 6 711.fr-cerfa/cerfa_11126.pdf2603.22026/Fig6New.pdf304× less memory and 9× less time for the figure. A 566-kilobyte file asking for 218 gigabytes to draw one page is not a page anybody can draw twice at once.
A clip is now the box it has narrowed down to plus the coverage inside that box; narrowing intersects the boxes first, so what is stored is never larger than the smaller of the two shapes.
Proved to change nothing
3 040 corpus pages drawn before and after, every page's pixels hashed, every hash identical.
What I removed again
I also tried keeping no coverage for a clip that lets everything through inside its box — what a clip to a rectangle ought to be. It never once fired: a rectangle's edge pixels are covered fractionally, so the grid is never exactly all ones. It is not in this PR. An optimisation that does not fire is complexity with nothing to show for it.
The form's remaining 6 GB is 2 140 clips that genuinely are large; the extreme cases are what this fixes.
Found by the robustness campaign, which measured it across 33 393 render stages: median 34 MB, p99 5 618 MB, worst 97 333 MB.
Stacked on
annotations. 100% statement coverage,go vetandgofmtclean, nine targets.