perf(device): pop retired deletions off the front in O(ready) (#116) #135

Merged
catbot merged 1 commit from claude/issue-116 into master 2026-06-17 21:38:28 +02:00
Member

Summary

Device::ReclaimDeletions is called once per frame (Window.cpp:802) and did an O(n) walk over the whole deletion queue plus an in-place survivor compaction. frameCounter is monotonic, so retireAfter is non-decreasing down the queue and the entries ready to reclaim are always a contiguous prefix.

This switches deletionQueue from std::vector to std::deque and pops the ready prefix off the front, stopping at the first entry still in flight (everything behind it is newer, hence also in flight) — O(ready) instead of O(queue).

Minor in practice (the queue is empty in steady state), but removes the per-frame full-queue scan.

Testing

crafter-build test --jobs=120 passed, including the deletion-queue tests DeferredDeletion and MeshDecompressStagingRelease which pin the exact retire-frame timing on a real headless Vulkan device.

(Note: parallel crafter-build test flakes in this sandbox due to concurrent git pull races on the shared external-dep cache — unrelated to this change; serial runs are green.)

Resolves #116

## Summary `Device::ReclaimDeletions` is called once per frame (`Window.cpp:802`) and did an O(n) walk over the whole deletion queue plus an in-place survivor compaction. `frameCounter` is monotonic, so `retireAfter` is non-decreasing down the queue and the entries ready to reclaim are always a contiguous **prefix**. This switches `deletionQueue` from `std::vector` to `std::deque` and pops the ready prefix off the front, stopping at the first entry still in flight (everything behind it is newer, hence also in flight) — **O(ready)** instead of O(queue). Minor in practice (the queue is empty in steady state), but removes the per-frame full-queue scan. ## Testing `crafter-build test --jobs=1` → **20 passed**, including the deletion-queue tests `DeferredDeletion` and `MeshDecompressStagingRelease` which pin the exact retire-frame timing on a real headless Vulkan device. (Note: parallel `crafter-build test` flakes in this sandbox due to concurrent `git pull` races on the shared external-dep cache — unrelated to this change; serial runs are green.) Resolves #116
ReclaimDeletions ran an O(n) walk + survivor compaction over the whole
deletion queue every frame. frameCounter is monotonic, so retireAfter is
non-decreasing down the queue and the entries ready to reclaim are always
a contiguous prefix. Switch deletionQueue from std::vector to std::deque
and pop the ready prefix off the front, stopping at the first entry still
in flight — O(ready) instead of O(queue).

Resolves #116

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
catbot merged commit 5948bb91c1 into master 2026-06-17 21:38:28 +02:00
catbot deleted branch claude/issue-116 2026-06-17 21:38:28 +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!135
No description provided.