Skip to content

perf: add SDF text layout cache and slim GlyphLayout#7

Merged
chiefcll merged 1 commit into
mainfrom
feat/sdf-layout-cache
May 9, 2026
Merged

perf: add SDF text layout cache and slim GlyphLayout#7
chiefcll merged 1 commit into
mainfrom
feat/sdf-layout-cache

Conversation

@chiefcll
Copy link
Copy Markdown
Contributor

@chiefcll chiefcll commented May 9, 2026

Summary

  • Add a module-level layoutCache Map in SdfTextRenderer that caches TextLayout results keyed by text properties (fontFamily, fontSize, letterSpacing, lineHeight, maxHeight, maxWidth, textAlign, text). Skips generateTextLayout entirely on cache hit.
  • Remove 4 unused fields from GlyphLayout (codepoint, glyphId, xOffset, yOffset) — verified these are never read by WebGlRenderer.addSdfQuads or any other consumer.

Motivation

Ported from upstream lightning-js/renderer@dbfd4e39. The layout cache avoids redundant glyph layout computation for text nodes with identical properties (e.g. repeated labels, list items). The GlyphLayout slimming reduces per-glyph object size by ~33%.

Test plan

  • All 94 existing tests pass (vitest run)
  • TypeScript compiles with no errors (tsc --noEmit)
  • Manual verification on target device with text-heavy scenes

🤖 Generated with Claude Code

Cache TextLayout results in a Map keyed by text properties to skip
redundant generateTextLayout calls for nodes with identical config.
Remove unused GlyphLayout fields (codepoint, glyphId, xOffset, yOffset)
that the renderer never reads, reducing per-glyph memory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chiefcll chiefcll merged commit 426a22c into main May 9, 2026
1 check failed
@chiefcll chiefcll deleted the feat/sdf-layout-cache branch May 9, 2026 14:35
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