perf(window): ring buffer for CRAFTER_TIMING frame times (#44) #76

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

Summary

Replaces the std::vector<nanoseconds> frameTimes + erase(begin()) in the
CRAFTER_TIMING frame loop with a fixed-size std::array<nanoseconds, 100>
ring buffer (head index + count).

The old code memmoved ~99 elements left on every frame once the 100-entry
window filled. LogTiming computes order-independent sum/avg/min/max, so the
ring's write order is irrelevant to the reported statistics — a ring buffer is
a drop-in replacement.

Scope is LOW / Small as filed; behind CRAFTER_TIMING only, so shipping
builds are unaffected.

Changes

  • interfaces/Crafter.Graphics-Window.cppm: frameTimes is now a
    std::array plus frameTimesHead / frameTimesCount, with a
    frameTimeCapacity constant.
  • implementations/Crafter.Graphics-Window.cpp: push writes into the ring and
    advances head; LogTiming iterates the first frameTimesCount valid entries.

Testing

  • crafter-build test3 passed (shipping, non-timing configuration).
  • Verified the edited regions compile under crafter-build -- --timing.

Note: pre-existing --timing build breakage (out of scope)

The --timing build does not currently link on master, independently of
this change: implementations/Crafter.Graphics-Window.cpp:647 and :841
reference renderTimings / renderer / RenderingElement, none of which are
declared in the window module anymore (confirmed by stashing this change and
rebuilding master — identical 3 errors). This looks like leftover code from a
renderer refactor and is unrelated to the frame-time buffer; fixing it is a
separate concern. My edited lines produce no errors.

Resolves #44

🤖 Generated with Claude Code

## Summary Replaces the `std::vector<nanoseconds> frameTimes` + `erase(begin())` in the `CRAFTER_TIMING` frame loop with a fixed-size `std::array<nanoseconds, 100>` ring buffer (head index + count). The old code memmoved ~99 elements left on every frame once the 100-entry window filled. `LogTiming` computes order-independent sum/avg/min/max, so the ring's write order is irrelevant to the reported statistics — a ring buffer is a drop-in replacement. Scope is `LOW` / `Small` as filed; behind `CRAFTER_TIMING` only, so shipping builds are unaffected. ## Changes - `interfaces/Crafter.Graphics-Window.cppm`: `frameTimes` is now a `std::array` plus `frameTimesHead` / `frameTimesCount`, with a `frameTimeCapacity` constant. - `implementations/Crafter.Graphics-Window.cpp`: push writes into the ring and advances head; `LogTiming` iterates the first `frameTimesCount` valid entries. ## Testing - `crafter-build test` — **3 passed** (shipping, non-timing configuration). - Verified the edited regions compile under `crafter-build -- --timing`. ## Note: pre-existing `--timing` build breakage (out of scope) The `--timing` build does **not** currently link on `master`, independently of this change: `implementations/Crafter.Graphics-Window.cpp:647` and `:841` reference `renderTimings` / `renderer` / `RenderingElement`, none of which are declared in the window module anymore (confirmed by stashing this change and rebuilding `master` — identical 3 errors). This looks like leftover code from a renderer refactor and is unrelated to the frame-time buffer; fixing it is a separate concern. My edited lines produce no errors. Resolves #44 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Replace the std::vector<nanoseconds> frameTimes plus
erase(begin()) with a fixed-size std::array ring buffer (head +
count). The previous code memmoved ~99 elements left every frame once
the window filled. LogTiming computes order-independent sum/avg/min/max,
so the ring's write order is irrelevant to the reported stats.

Behind CRAFTER_TIMING only; shipping builds are unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
catbot merged commit 626cc6f5c8 into master 2026-06-16 17:25:58 +02:00
catbot deleted branch claude/issue-44 2026-06-16 17:25:58 +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!76
No description provided.