perf(ui): transparent shaped-run cache lookup, no string copy on hit (#122) #141
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!141
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "claude/issue-122"
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?
Problem
UIRenderer::ShapeTextbuiltShapedRunKey{..., std::string(utf8)}beforefind()unconditionally — including on cache hits, on the per-frameonBuildpath. N labels meant N string copies + hashes (plus heap frees for non-SSO strings) every frame, partially defeating the shaped-run cache.Fix
is_transparenthash and equality functors toshapedRuns_.ShapedRunViewKey {const Font*, float, std::array<float,4>, std::string_view}whosetextviews the caller'sutf8directly.std::stringonly on a miss, for theemplace.A cache hit now copies and hashes no string. Hash values are unchanged (the existing hash already routed
textthroughstd::hash<std::string_view>), so existing entries match identically.Testing
crafter-build test— all 23 tests pass, includingShapeTextCache, which asserts a hit is byte-identical to the miss path, leaves the atlas clean, and that distinct color/pxSize/font are distinct entries.Resolves #122
ShapeText built ShapedRunKey{..., std::string(utf8)} before find() unconditionally — even on cache hits, on the per-frame onBuild path. N labels meant N string copies + hashes (+ frees for non-SSO strings) every frame, partially defeating the run cache. Add is_transparent hash + equality functors on shapedRuns_ and probe with a borrowing ShapedRunViewKey {const Font*, float, array<float,4>, string_view}. The owning std::string is now materialised only on a miss, for emplace. Cache hits copy and hash no string. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>