Skip to content

perf(clip): cache rasterized coverage masks - #516

Open
kivutar wants to merge 1 commit into
gogpu:mainfrom
kivutar:perf/cache-clip-mask
Open

perf(clip): cache rasterized coverage masks#516
kivutar wants to merge 1 commit into
gogpu:mainfrom
kivutar:perf/cache-clip-mask

Conversation

@kivutar

@kivutar kivutar commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • cache the immutable pixel coverage mask for each non-rectangular clip-stack state
  • share cached masks across unchanged clones and restore the previous cache on Pop
  • reuse the cached mask from Context.applyClipToPaint instead of rasterizing the complete clip for every fill

Motivation

Context.applyClipToPaint rebuilt the entire non-rectangular clip mask on every fill. A downstream fullscreen UI repaint containing a rounded window regressed to about 553 ms at 1.333x scaling after the new clip architecture; reusing the mask brings the same repaint back to about 58 ms.

The cache is state-local, bounded by the live clip stack, immutable after initialization, and synchronized so unchanged clones can rasterize concurrently. Mutations receive a new cache, while Pop restores the previous state and its mask.

Validation

  • go test . ./internal/clip -count=1
  • go test -race . ./internal/clip -count=1
  • go vet ./...
  • staticcheck . ./internal/clip
  • cached applyClipToPaint: 105-106 ns/op, 16 B/op, 1 alloc/op

@kivutar
kivutar requested a review from kolkov as a code owner August 17, 2026 15:51
@kivutar
kivutar force-pushed the perf/cache-clip-mask branch from 1094d6c to 2843669 Compare August 17, 2026 16:03
@kivutar

kivutar commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

CI is currently failing during action setup because GitHub's codeload endpoints return 429/5xx errors; no failing job reached this branch's code. I retriggered the workflow once by refreshing the head commit, but the same infrastructure outage affected more runners and fork authors cannot rerun upstream workflows. Local validation is green as documented in the PR description.

@kivutar

kivutar commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Can we re-run the CI on this please?

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