[perf][MEDIUM] Per-frame text re-shaping for static strings #52
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Catcrafts/Crafter.Graphics#52
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Subsystem: Font / text shaping
Location:
implementations/Crafter.Graphics-UI-Shared.cpp:46-86Impact: MEDIUM · Effort: Medium
Problem
ShapeTextre-decodes UTF-8, re-looks-up every glyph, and recomputes layout every frame for static strings (called fromDrawText/EmitCenteredLabelinside per-frameonBuild).EmitCenteredLabelandDrawTextalso do a second full pass over the glyphs to apply centering.Proposed fix
Shaped-run cache keyed by
(Font*, pxSize, hash(utf8), color)->vector<GlyphItem>stored origin-relative; on a hit, translate by(x, baselineY)andmemcpyinto the buffer (GlyphItem is a 48-byte POD). Fold the centering shift intoShapeTextto drop the second loop.Correctness caveat
Pure CPU memoization — the buffer is fully rewritten + re-flushed every frame regardless, so caching is byte-equivalent. On a cache miss the builder must still call
Ensureso new glyphs rasterize/dirty the atlas. Invalidate on Font destruction.