Skip to content

perf(text): cache CPU glyph rasterization results - #517

Open
kivutar wants to merge 2 commits into
gogpu:mainfrom
kivutar:perf/cache-cpu-text
Open

perf(text): cache CPU glyph rasterization results#517
kivutar wants to merge 2 commits into
gogpu:mainfrom
kivutar:perf/cache-cpu-text

Conversation

@kivutar

@kivutar kivutar commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • cache final AA and aliased CPU glyph masks per FontSource
  • cache immutable TrueType-hinted outlines per font size and glyph
  • reuse the hinted outline between advance measurement and rasterization
  • bound both new caches to 512 entries per owning cache

Correctness and lifecycle

The final-mask key includes the glyph ID, exact size and subpixel coordinates, hinting mode, and raster mode. Each FontSource owns its cache, so different fonts and weights cannot contaminate one another. FontSource.Close synchronizes with lazy cache initialization before clearing it. Errors and successful masks are deterministic and cached together.

Hinted outlines are immutable after construction. A per-entry sync.Once coalesces concurrent work, while the sharded LRU bounds retained glyphs.

Benchmarks

Upstream main:

BenchmarkDrawCPUGlyphMaskCacheHit       1.90-2.02 ms/op   1,173,345-1,173,356 B/op   5766 allocs/op
BenchmarkFontTTHint_GlyphOutline         847-875 us/op       74,338 B/op             18 allocs/op

This branch:

BenchmarkDrawCPUGlyphMaskCacheHit       16.9-17.5 us/op       3,408 B/op             39 allocs/op
BenchmarkFontTTHint_GlyphOutline        51.2-53.5 ns/op           0 B/op              0 allocs/op

Validation

  • go test ./text -count=1
  • go test -race ./text -count=1
  • go vet ./...
  • staticcheck ./text/...

@kivutar
kivutar requested a review from kolkov as a code owner August 17, 2026 15:54
@kivutar
kivutar force-pushed the perf/cache-cpu-text branch from 78e1193 to 9697ac5 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