[perf] ShapeText heap-allocates the cache-key std::string on every call, including hits (UI-Shared.cpp) #122

Closed
opened 2026-06-17 21:18:54 +02:00 by jorijnvdgraaf · 0 comments

Found by an adversarially-verified performance audit (confirmed real after a skeptic pass).

Location: implementations/Crafter.Graphics-UI-Shared.cpp:78-79
Severity: medium · Effort: moderate · Category: allocation

Problem

ShapeText builds ShapedRunKey{..., std::string(utf8)} before find() unconditionally, including on cache hits, on the per-frame onBuild path. N labels = N string copies + hashes (+ frees for non-SSO strings) per frame, partially defeating the run cache.

Fix

is_transparent transparent hash + equality on shapedRuns_; probe with a view-key {const Font*, float, array<float,4>, string_view} and materialize the owning std::string only on miss for emplace.

Found by an adversarially-verified performance audit (confirmed real after a skeptic pass). **Location:** `implementations/Crafter.Graphics-UI-Shared.cpp:78-79` **Severity:** medium · **Effort:** moderate · **Category:** allocation ### Problem `ShapeText` builds `ShapedRunKey{..., std::string(utf8)}` before `find()` unconditionally, including on cache hits, on the per-frame `onBuild` path. N labels = N string copies + hashes (+ frees for non-SSO strings) per frame, partially defeating the run cache. ### Fix `is_transparent` transparent hash + equality on `shapedRuns_`; probe with a view-key `{const Font*, float, array<float,4>, string_view}` and materialize the owning `std::string` only on miss for `emplace`.
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#122
No description provided.