umem: write the bind log on a dedicated thread #136

Closed
github-bot wants to merge 1 commit from github-bot/gh-136 into main AGit
Owner

@⁠TheRifai on GitHub · 2026-12-01 20:18 UTC · original
TheRifai:bindlog-async → main · +98 −47 · 4 files · 1 commits · closed without merging

What

bindlog::line and bindlog::flushed wrote the 64 KiB buffer to disk while holding the log mutex, so a slow disk blocked every thread logging a bind (docs/TASKS.md, "The bind log write under its lock stalls every thread for seconds"): the renderer, the descriptor helper, and the remapper's bind flush. The hot path now only appends to the buffer under the lock and hands full buffers to one dedicated writer thread. A failed hand-off is counted (umem::bindlog_dropped()) and shown on the stats line rather than waited on (rule 31). No Vulkan behaviour changes.

The reference

No console counterpart: a diagnostic log must never change frame timing. The maintainer's two runs attributed 11,340.7 ms and 2,290.2 ms of renderer lock wait to umem/src/bindlog.rs:46.

Evidence

  • cargo check -p umem/-p vkback, 21 umem tests and 160 vkback tests, and the build all pass. Two new tests: a writer that sleeps 300 ms does not delay a line/flush (<100 ms), and a dropped writer increments the counter.
  • Async build, house start, 110 s with UMEM_BINDLOG: a valid 45 MB log (806,856 lines), bind log buffers dropped 0, renderer lock waits 0.7 ms total (bindlog.rs:44 0.4 ms over 5 uncontended-ish waits), no bind log write span on a hot thread.
  • Same run on unmodified main 7131e3d: valid 53 MB log, renderer lock waits 0.2 ms. The multi-second stall needs the maintainer's slow-disk/PSI conditions, which did not reproduce locally; the change removes the file write from under the lock by construction.
  • Both runs hit the known exit-1 fault after reaching the world; neither is a performance claim. Runs: /tmp/opencode/capture/bindlog-async/, /tmp/opencode/capture/bindlog-main/.

Checklist (docs/AGENTS.md)

  • One topic; docs/TASKS.md not edited (rule 29/31)
  • No fallback, constant, switch, queue, unsafe or translator output changed (rules 2/9b/33/35/36/27)
  • Comments say what is true now (rule 3)
  • Nothing from the title, no non-free data pointers (hard constraints)
**@⁠TheRifai** on GitHub · 2026-12-01 20:18 UTC · [original](https://github.com/vktory6/VKtory/pull/136) `TheRifai:bindlog-async` → `main` · +98 −47 · 4 files · 1 commits · closed without merging ## What `bindlog::line` and `bindlog::flushed` wrote the 64 KiB buffer to disk **while holding the log mutex**, so a slow disk blocked every thread logging a bind (docs/TASKS.md, "The bind log write under its lock stalls every thread for seconds"): the renderer, the descriptor helper, and the remapper's bind flush. The hot path now only appends to the buffer under the lock and hands full buffers to one dedicated writer thread. A failed hand-off is counted (`umem::bindlog_dropped()`) and shown on the stats line rather than waited on (rule 31). No Vulkan behaviour changes. ## The reference No console counterpart: a diagnostic log must never change frame timing. The maintainer's two runs attributed 11,340.7 ms and 2,290.2 ms of renderer lock wait to `umem/src/bindlog.rs:46`. ## Evidence - `cargo check -p umem`/`-p vkback`, 21 umem tests and 160 vkback tests, and the build all pass. Two new tests: a writer that sleeps 300 ms does not delay a line/flush (<100 ms), and a dropped writer increments the counter. - Async build, house start, 110 s with `UMEM_BINDLOG`: a valid 45 MB log (806,856 lines), `bind log buffers dropped 0`, renderer lock waits `0.7 ms` total (`bindlog.rs:44` 0.4 ms over 5 uncontended-ish waits), no `bind log write` span on a hot thread. - Same run on unmodified main `7131e3d`: valid 53 MB log, renderer lock waits `0.2 ms`. The multi-second stall needs the maintainer's slow-disk/PSI conditions, which did not reproduce locally; the change removes the file write from under the lock by construction. - Both runs hit the known exit-1 fault after reaching the world; neither is a performance claim. Runs: `/tmp/opencode/capture/bindlog-async/`, `/tmp/opencode/capture/bindlog-main/`. ## Checklist (docs/AGENTS.md) - [x] One topic; `docs/TASKS.md` not edited (rule 29/31) - [x] No fallback, constant, switch, queue, `unsafe` or translator output changed (rules 2/9b/33/35/36/27) - [x] Comments say what is true now (rule 3) - [x] Nothing from the title, no non-free data pointers (hard constraints)
`bindlog::line` and `bindlog::flushed` wrote the 64 KiB buffer to disk while holding the log's mutex, so a slow disk stalled every thread that logged a bind (renderer 11.3 s and 2.3 s in two maintainer runs, with the descriptor helper and the remapper stuck on the same lock). The hot path now appends to the buffer under the lock and hands full buffers to one writer thread; a send failure is counted instead of waited on, and the dropped count appears on the stats line. Two unit tests cover a slow writer and a dropped buffer.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:20:08 +00:00
Author
Owner

@⁠TheRifai on GitHub · 2026-12-01 20:19 UTC · original

Superseded: main merged 8e558b7 (#134, "umem: write the bind log on a writer thread, never block a caller") while this PR was open, and it now conflicts. Our implementation came from the same TASKS entry and has the same shape (dedicated writer thread, counted drops); the extra stats line and two unit tests here are not worth a rebase over the merged fix. Please close this one rather than merging; I won't close it myself.

**@⁠TheRifai** on GitHub · 2026-12-01 20:19 UTC · [original](https://github.com/vktory6/VKtory/pull/136#issuecomment-7324476538) Superseded: main merged `8e558b7` (#134, "umem: write the bind log on a writer thread, never block a caller") while this PR was open, and it now conflicts. Our implementation came from the same TASKS entry and has the same shape (dedicated writer thread, counted drops); the extra stats line and two unit tests here are not worth a rebase over the merged fix. Please close this one rather than merging; I won't close it myself.
github-bot closed this pull request 2026-12-01 20:26:25 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-01 20:22 UTC · original

Thanks for saying so, and sorry for the overlap. #134 landed first, with the same shape. Closing as superseded, as you asked.

This is the third duplicate today (#130, #131, now this), because TASKS.md doesn't show who is on a task. We're working on a way to mark tasks as taken, so this stops happening.

If you want, the live drop counter in the stats line is still a useful small follow-up on top of #134. Right now #134 reports drops only at detach.

**@⁠vktory6** on GitHub · 2026-12-01 20:22 UTC · [original](https://github.com/vktory6/VKtory/pull/136#issuecomment-7324567989) Thanks for saying so, and sorry for the overlap. #134 landed first, with the same shape. Closing as superseded, as you asked. This is the third duplicate today (#130, #131, now this), because TASKS.md doesn't show who is on a task. We're working on a way to mark tasks as taken, so this stops happening. If you want, the live drop counter in the stats line is still a useful small follow-up on top of #134. Right now #134 reports drops only at detach.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.