Repository navigation
perf(paint): normalise blitImage's source once, not once per pixel - #289
Merged
Merged
Conversation
Round 175's own PR (#288) flagged blitImage as a known, smaller instance of the exact same anti-pattern blitTileClipped had: every blitted pixel went through the image.Image/color.Color interface (heap-allocating to box the returned value, and double-applying alpha the same way At().RGBA() always premultiplies, which was then passed as blendPixel's straight colour argument alongside the same alpha again as coverage). Unmeasured at the time; measured now with BenchmarkBlitImageLargePhoto (a 1920x1080 solid image): the cost is real, tens of milliseconds for a single full-bleed photo. blitImage normalises src to *image.NRGBA once internally (toNRGBA, already added in #288) and reads it via NRGBAAt directly. No call site changes needed since the function's own signature is unchanged -- all 5 of its callers (icon-only button, leading/trailing button icons, object-fit image tiling's non-tiling branch, rotated-box compositing) benefit automatically. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
blitTileClipped, and flaggedblitImageas a known, smaller, unmeasured instance of the same thing.BenchmarkBlitImageLargePhoto(a single 1920x1080 image) shows real cost, tens of milliseconds per large photo blit.blitImagenormalises its source to*image.NRGBAonce internally (reusingtoNRGBAfrom fix(paint): normalise background-repeat tiles once, not once per pixel #288) and reads viaNRGBAAt. Signature unchanged, so all 5 call sites (icon-only buttons, leading/trailing button icons, object-fit image tiling, rotated-box compositing) benefit with no call-site changes.Test plan
go test ./...— all packages pass unchanged.BenchmarkBlitImageLargePhotoadded for future regression tracking.🤖 Generated with Claude Code