perf(text): cache shaped runs in ShapeText (#52) #82
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Catcrafts/Crafter.Graphics!82
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "claude/issue-52"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
ShapeTextre-decoded UTF-8, re-looked-up every glyph, and recomputed layout every frame for static strings (DrawText/EmitCenteredLabelrun inside per-frameonBuild). The callers also did a second full pass over the glyphs just to apply alignment.This adds a shaped-run cache keyed by
(Font*, pxSize, color, utf8)holding an origin-relativevector<GlyphItem>. On a hit, ShapeText skips decode/lookup/layout and just translates the cached run into the output buffer by(x + alignShift, baselineY). The alignment shift (Center =-advance/2, Right =-advance) is folded into ShapeText's single pass, so both callers drop their second loop.Correctness
Ensurefor every glyph (rasterise + dirty); a hit doesn't, which is safe because atlas entries are never evicted once placed.UIRenderer::InvalidateFont(font)drops a font's runs before it is destroyed — the run cache, likeFontAtlas's glyph cache, keys on theFont*.TextAlignmoved from the:UIComponentspartition to:UIso ShapeText can take it; transparent to users whoimport Crafter.Graphics.Tests
New
ShapeTextCachetest (15 checks, headless Vulkan device, no swapchain): hit == miss byte-for-byte, hits don't touch the atlas, miss dirties it, translate-only move, Center/Right alignment fold,outCapacitytruncation still reports full advance, re-shape afterInvalidateFont, distinct color/pxSize entries.Native +
wasm32-wasip1both build clean (the changed code is shared across backends).Resolves #52