perf(window): ring buffer for CRAFTER_TIMING frame times (#44)
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>
This commit is contained in:
parent
050a44d118
commit
41d99890c1
2 changed files with 26 additions and 17 deletions
|
|
@ -164,7 +164,14 @@ export namespace Crafter {
|
|||
std::chrono::nanoseconds vblank;
|
||||
std::chrono::nanoseconds totalFrame;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> frameEnd;
|
||||
std::vector<std::chrono::nanoseconds> frameTimes;
|
||||
// Fixed-size ring buffer of the most recent frame times. LogTiming does
|
||||
// order-independent sum/avg/min/max, so head position is irrelevant to
|
||||
// the reported stats; this avoids the per-frame memmove a vector::erase
|
||||
// at the front would incur once full.
|
||||
static constexpr std::size_t frameTimeCapacity = 100;
|
||||
std::array<std::chrono::nanoseconds, frameTimeCapacity> frameTimes{};
|
||||
std::size_t frameTimesHead = 0;
|
||||
std::size_t frameTimesCount = 0;
|
||||
void LogTiming();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue