Repository navigation
Carry a rectangular clip as a rectangle instead of rasterising it - #66
Merged
Merged
Conversation
91% of the clips a PDF sets are `re W n` -- 57367 of 63038 over two
corpora of 3215 documents -- and every one of the 192 on the page where
this renderer was furthest behind poppler. Each was rasterised into a
coverage grid: an edge list, a sweep, and w*h float32 to store a shape
four numbers describe.
The interpreter already knows. A path built by one `re` and nothing else,
under a transform that does not rotate it, is an axis-aligned rectangle
before it is built, so the clip keeps the rectangle and never asks the
rasteriser.
the page it was found on 165ms -> 12ms draw 14x
What go-gfx/gfx v0.34.0's vector.Rect answers is what the rasteriser
would have put in that grid, BIT FOR BIT, which is what makes this a
substitution rather than an approximation -- through float32 and back,
because a link that stores a grid stores float32.
Rect.Whole gives the pixels it covers entirely, which answers most of
them with two comparisons and no memory touched at all. It was built
because the rectangle form measured 13% slower on a scanned page; that
measurement was taken while a 3215-document sweep was running, and does
not reproduce on a quiet machine. The optimisation is sound and its
reason was not.
3215 documents rendered before and after and compared as PNG bytes: 3215
byte-identical, 0 different.
The coverage gate asked for the one case in which a rectangle link
answers zero, and it is a real one: the rasteriser samples four
sub-scanlines a row, so a rectangle thinner than a quarter of a pixel can
fall BETWEEN two of them -- a box with nothing in it.
This was referenced Nov 22, 2026
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.
91% of the clips a PDF sets are
re W n— 57 367 of 63 038 over two corpora of 3215 documents — and every one of the 192 on the page where this renderer was furthest behind poppler.Each was rasterised into a coverage grid: an edge list, a sweep, and
w*hfloat32 to store a shape four numbers describe.The interpreter already knows
A path built by one
reand nothing else, under a transform that does not rotate it, is an axis-aligned rectangle before it is built. So the clip keeps the rectangle and never asks the rasteriser.pdftoppmdraws that page in 70 ms for the whole process. It was our worst document at 2.33× behind; it is not any more.Bit for bit, not approximately
What
go-gfx/gfxv0.34.0'svector.Rectanswers is what the rasteriser would have put in that grid — throughfloat32and back, because a link that stores a grid storesfloat32.3215 documents rendered before and after and compared as PNG bytes: 3215 byte-identical, 0 different.
A correction
Rect.Whole— the pixels a rectangle covers entirely, answered with two comparisons and no memory touched — was built because the rectangle form measured 13% slower on a scanned page. That measurement was taken while a 3215-document sweep was running, and does not reproduce on a quiet machine:Wholeirrigationrequir1340fort.pdfThe optimisation is sound and well tested; its reason was not. Saying so here rather than letting the commit message stand as the record.
What the coverage gate asked for
The one case in which a rectangle link answers zero, and it is real: the rasteriser samples four sub-scanlines a row, so a rectangle thinner than a quarter of a pixel can fall between two of them — a box with nothing in it.
TestARectangleThinnerThanASubScanlinepins it, and checks the rectangle against the rasteriser pixel for pixel on the same shape.🤖 Generated with Claude Code