Look up views once per range in watch::writing, and drop ended pins #67

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

@⁠romainhedouin on GitHub · 2026-11-25 13:16 UTC · original
romainhedouin:perf/watch-writing-one-lock → main · +29 −15 · 1 files · 1 commits · closed without merging

watch::writing runs for every copy into title memory, every copy-back, every readback row, every ReadFile and every raw DirectStorage request. For each 64 KiB block of the range it locked the views table and copied that block's list of views into a new Vec, even for pages with a single view that it then skipped. It now locks the views table once for the whole range and only collects the other views of pages that have several. It also drops pins that have ended when adding a new one (they end in the order they are made, so this is a pop from the front); before, they were only dropped on the slow path of guard() and could pile up, making every pin check scan them. Same pins, same blocks opened.

Per writing() call over N blocks Before After
Views-table locks N 1
Allocations (single-view pages) 1 per block 0
Model benchmark, 16 blocks, single-view pages 640–800 ns 330–415 ns
Model benchmark, 256 MiB, no views 91 µs 58 µs

"Model benchmark" = the same logic copied into a standalone program and timed in release mode on a Mac, not in the game. The model asserts identical pins and opened blocks for the old and new code. Type-checked for Windows (cargo clippy --target x86_64-pc-windows-msvc, with and without --all-features, no new warnings); not run.

🤖 Generated with Claude Code

**@⁠romainhedouin** on GitHub · 2026-11-25 13:16 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/67) `romainhedouin:perf/watch-writing-one-lock` → `main` · +29 −15 · 1 files · 1 commits · closed without merging `watch::writing` runs for every copy into title memory, every copy-back, every readback row, every `ReadFile` and every raw DirectStorage request. For each 64 KiB block of the range it locked the views table and copied that block's list of views into a new `Vec`, even for pages with a single view that it then skipped. It now locks the views table once for the whole range and only collects the other views of pages that have several. It also drops pins that have ended when adding a new one (they end in the order they are made, so this is a pop from the front); before, they were only dropped on the slow path of `guard()` and could pile up, making every pin check scan them. Same pins, same blocks opened. | Per `writing()` call over N blocks | Before | After | |---|---|---| | Views-table locks | N | 1 | | Allocations (single-view pages) | 1 per block | 0 | | Model benchmark, 16 blocks, single-view pages | 640–800 ns | 330–415 ns | | Model benchmark, 256 MiB, no views | 91 µs | 58 µs | "Model benchmark" = the same logic copied into a standalone program and timed in release mode on a Mac, not in the game. The model asserts identical pins and opened blocks for the old and new code. Type-checked for Windows (`cargo clippy --target x86_64-pc-windows-msvc`, with and without `--all-features`, no new warnings); not run. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:34:54 +00:00
@ -663,0 +661,4 @@
// at the views for the whole range, and a list only of the other views of
// pages with several (a lock and a list for each block before, which
// every copy into title memory waited for under the guards' lock).
let others = {
Author
Owner

@⁠gut0to on GitHub · 2026-11-25 15:08 UTC · original

The existing alias tests write through a mapped view and exercise the exception path, but they do not call writing() on a range spanning aliased blocks. Could one test verify that this bulk alias collection leaves each corresponding other view writable and reports it on the next guard check? AI-assisted review; I checked the changed range walk against the existing alias tests.

**@⁠gut0to** on GitHub · 2026-11-25 15:08 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/67#discussion_r4696896650) The existing alias tests write through a mapped view and exercise the exception path, but they do not call writing() on a range spanning aliased blocks. Could one test verify that this bulk alias collection leaves each corresponding other view writable and reports it on the next guard check? AI-assisted review; I checked the changed range walk against the existing alias tests.
Author
Owner

@⁠gut0to on GitHub · 2026-11-25 15:08 UTC · original · reviewed

AI-assisted review: I checked the changed behavior and the associated test coverage.

**@⁠gut0to** on GitHub · 2026-11-25 15:08 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/67#pullrequestreview-6060183572) · **reviewed** AI-assisted review: I checked the changed behavior and the associated test coverage.
github-bot closed this pull request 2026-11-27 01:00:04 +00:00
Author
Owner

@⁠romainhedouin on GitHub · 2026-11-26 22:24 UTC · original

Closing: on a-publier, watch::writing no longer pins or walks views block by block. It takes the guards' lock only when the PROTECTED bitmap shows a protected block (watch.rs:3222).

**@⁠romainhedouin** on GitHub · 2026-11-26 22:24 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/67#issuecomment-7204651217) Closing: on `a-publier`, `watch::writing` no longer pins or walks views block by block. It takes the guards' lock only when the `PROTECTED` bitmap shows a protected block (watch.rs:3222).

Pull request closed

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