perf(text): fold Ensure+Lookup into FontAtlas::EnsureAndGet (#53) #84

Merged
catbot merged 1 commit from claude/issue-53 into master 2026-06-16 17:44:21 +02:00
Member

Problem

Per codepoint, ShapeText did cache_.contains(key) (inside Ensure) immediately followed by cache_.find(key) (inside Lookup) — two independent hashes + node-chases of the same key, every glyph every frame even in steady state.

Fix

Add FontAtlas::EnsureAndGet returning const Glyph*: a single find, insert-on-miss, returns &it->second. It returns nullptr only on ShelfPlace failure, preserving the existing if (g==nullptr) continue; skip behavior. A glyph with no SDF coverage (e.g. space) still returns a valid pointer. Ensure now delegates to EnsureAndGet.

The call site in ShapeText runs on the shaped-run cache miss path (#52), so this trims work whenever a new run is shaped.

Tests

crafter-build test — 4 passed, including ShapeTextCache.

Resolves #53

### Problem Per codepoint, `ShapeText` did `cache_.contains(key)` (inside `Ensure`) immediately followed by `cache_.find(key)` (inside `Lookup`) — two independent hashes + node-chases of the same key, every glyph every frame even in steady state. ### Fix Add `FontAtlas::EnsureAndGet` returning `const Glyph*`: a single `find`, insert-on-miss, returns `&it->second`. It returns `nullptr` only on `ShelfPlace` failure, preserving the existing `if (g==nullptr) continue;` skip behavior. A glyph with no SDF coverage (e.g. space) still returns a valid pointer. `Ensure` now delegates to `EnsureAndGet`. The call site in `ShapeText` runs on the shaped-run cache miss path (#52), so this trims work whenever a new run is shaped. ### Tests `crafter-build test` — 4 passed, including `ShapeTextCache`. Resolves #53
Per glyph, ShapeText did cache_.contains(key) (in Ensure) then
cache_.find(key) (in Lookup) — two independent hashes + node-chases of
the same key. Add EnsureAndGet returning const Glyph* with a single
find, insert-on-miss, returning &it->second. It returns nullptr only on
ShelfPlace failure, preserving the existing `if (g==nullptr) continue;`
behavior. Ensure now delegates to it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
catbot merged commit 0b00d9d680 into master 2026-06-16 17:44:21 +02:00
catbot deleted branch claude/issue-53 2026-06-16 17:44:21 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Catcrafts/Crafter.Graphics!84
No description provided.