[perf][LOW] Ensure()+Lookup() do two hash-map probes per glyph #53

Closed
opened 2026-06-16 16:51:32 +02:00 by jorijnvdgraaf · 0 comments

Subsystem: Font / text shaping
Location: implementations/Crafter.Graphics-UI-Shared.cpp:61-82
Impact: LOW · Effort: Small

Problem

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

Proposed fix

EnsureAndGet returning const Glyph* (one find, insert-on-miss, return &it->second).

Correctness caveat

EnsureAndGet must return nullptr on ShelfPlace failure to preserve the existing if (g==nullptr) continue; behavior. Largely subsumed by the shaped-run cache issue.

**Subsystem:** Font / text shaping **Location:** `implementations/Crafter.Graphics-UI-Shared.cpp:61-82` **Impact:** LOW · **Effort:** Small ### Problem Per codepoint, `Ensure` does `cache_.contains(key)` then `Lookup` immediately does `cache_.find(key)` — two independent hashes + node-chases of the same key, every glyph every frame, even in steady state. ### Proposed fix `EnsureAndGet` returning `const Glyph*` (one `find`, insert-on-miss, return `&it->second`). ### Correctness caveat `EnsureAndGet` must return `nullptr` on `ShelfPlace` failure to preserve the existing `if (g==nullptr) continue;` behavior. Largely subsumed by the shaped-run cache issue.
Sign in to join this conversation.
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#53
No description provided.