[perf] DrawInputField recomputes caret X via full-prefix walk every frame (InputField.cpp) #128

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

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

Location: implementations/Crafter.Graphics-InputField.cpp:151-153
Severity: low · Effort: moderate · Category: cpu

Problem

For a focused, caret-visible field, DrawInputField walks the whole cursor prefix via GetLineWidth every frame even though only caretVisible (the blink) changes. Cost is bounded — AdvanceUnits is memoized (no stbtt), only the single focused field hits it, and the prefix is short for typical fields.

Fix

Memoize caretX keyed on (value, cursorPos, fontSize). Needs a mutable/external cache since DrawInputField takes const InputField&.

Found by an adversarially-verified performance audit (confirmed real after a skeptic pass). **Location:** `implementations/Crafter.Graphics-InputField.cpp:151-153` **Severity:** low · **Effort:** moderate · **Category:** cpu ### Problem For a focused, caret-visible field, `DrawInputField` walks the whole cursor prefix via `GetLineWidth` every frame even though only `caretVisible` (the blink) changes. Cost is bounded — `AdvanceUnits` is memoized (no stbtt), only the single focused field hits it, and the prefix is short for typical fields. ### Fix Memoize `caretX` keyed on `(value, cursorPos, fontSize)`. Needs a mutable/external cache since `DrawInputField` takes `const InputField&`.
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#128
No description provided.