Skip to content

perf(paint): normalise blitImage's source once, not once per pixel - #289

Merged
tannevaled merged 1 commit into
mainfrom
fix/blitimage-nrgba-once
Oct 18, 2026
Merged

tannevaled merged 1 commit into
mainfrom
fix/blitimage-nrgba-once

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Summary

  • Round 175's PR (fix(paint): normalise background-repeat tiles once, not once per pixel #288) fixed this exact anti-pattern (interface-boxing + double-applied alpha) in blitTileClipped, and flagged blitImage as a known, smaller, unmeasured instance of the same thing.
  • Measured now: BenchmarkBlitImageLargePhoto (a single 1920x1080 image) shows real cost, tens of milliseconds per large photo blit.
  • Fix: blitImage normalises its source to *image.NRGBA once internally (reusing toNRGBA from fix(paint): normalise background-repeat tiles once, not once per pixel #288) and reads via NRGBAAt. 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.
  • New BenchmarkBlitImageLargePhoto added for future regression tracking.

🤖 Generated with Claude Code

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>
@tannevaled
tannevaled merged commit f39458e into main Oct 18, 2026
7 checks passed
@tannevaled
tannevaled deleted the fix/blitimage-nrgba-once branch October 18, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant