Repository navigation
Stop allocating a coverage grid for every mark made through a clip - #79
Merged
Merged
Conversation
mask() copied its input into a fresh []float64 on every call. It has to copy -- the rasteriser hands back its own scratch and a tiling pattern reads that again for the next tile -- but it does not have to allocate. The buffer is now kept on the renderer. Reuse is safe although paint() is re-entrant, because the buffer's whole life is inside one paint: mask fills it, Composite reads it, record reads it, and nothing between those runs a content stream. Argued, and then checked: the corpus's worst page is a 2.4 KB file whose Type 3 glyph fills with a pattern that shows the same glyph, which is exactly the re-entrant case, and it renders byte-identically. WHAT THIS BUYS IS MEMORY, NOT TIME, and the measurement says so plainly: that page 2267.61 MB -> 1378.90 MB -39% (mask alone was 907.79 MB) cerfa_12496.pdf 547.86 MB -> 525.19 MB -4% a uk-govuk form 69.04 MB -> 63.32 MB -8% b31820797.pdf 1192.60 MB -> 1187.95 MB -0.4% Time: no measurable change. 1266 ms against 1339 ms on the worst page, min of four, either side of a noise floor of about 1%. GOGC=off does not make that page faster either, so its 1.3 s is not the collector and removing the garbage was never going to be the fix. All 3 215 corpus documents render byte-identical. Coverage stays at 100.0%.
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.
mask()copied its input into a fresh[]float64on every call. It has tocopy — the rasteriser hands back its own scratch and a tiling pattern reads that
again for the next tile — but it does not have to allocate.
Reuse is safe although
paint()is re-entrant, because the buffer's whole life isinside one
paint:maskfills it,Compositereads it,recordreads it, andnothing between those runs a content stream. Argued, then checked: the
corpus's worst page is a 2.4 KB file whose Type 3 glyph fills with a pattern that
shows the same glyph — exactly the re-entrant case — and it renders
byte-identically.
What this buys is memory, not time
cerfa_12496.pdfuk-govukformb31820797.pdfmaskalone accounted for 907.79 MB on the first of those.Time: no measurable change. 1266 ms against 1339 ms on the worst page, min of
four, either side of a noise floor of about 1%.
GOGC=offdoes not make that pagefaster either — so its 1.3 s is not the collector, and removing the garbage was
never going to be the fix. Where that 1.3 s actually goes is still open.
All 3 215 corpus documents render byte-identical. Coverage stays at 100.0%.
🤖 Generated with Claude Code