Reuse a live window that holds an ask, so its memory is copied once #55

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

@⁠wymd-wn118 on GitHub · 2026-11-25 22:28 UTC · original
wymd-wn118:window-reuse-holds-the-ask → main · +59 −1 · 1 files · 1 commits · closed without merging

AI-generated and unverified. Drafted by an AI agent (DeepSeek) from a single run of the title, with no human review. About 60 lines, one function, plus two tests. Judge whether to read on that basis.

What

A loose window is looked up by its (start, len) exactly, but the two kinds of ask make different lengths for the same memory: an ask without a length takes a tail of its 4 MiB cell (tail_of), one with a length takes the grid's window (window_of). An ask that found no window of its own then made a second one over memory another window already held, and that memory was copied once for each.

loose now takes a window that begins at or below the ask, no lower than the ask's own line, and holds all of it. That is holder_below, split out from the map walk so it is tested without a card.

Measured

In the world, VICTORY_WINDOW_TAILS=1 VICTORY_WINDOW_KB=256, from the memory line (the N MB of windows lie over M MB of title memory):

windows title memory held copied twice
before 2,496 MB 1,636 MB 34-38%
after 1,499 MB 1,198 MB 17-20%

Repeat ratios sampled across a run, before: 864, 886, 999, 1,049, 953, 860 MB (34-38%). After: 226, 271, 301 MB (17-20%).

Limitation: this is one title, one configuration, and the scene reached differs between runs. The window and cover numbers above are what moved; frame times alongside them are not comparable run to run.

Not a duplicate

Checked against all 53 open PRs: none changes the body of loose() or takes a window that holds an ask.

  • #46 and #53 (cache registered shadow buffer lookups) only call loose - they cache registered-buffer hits and state that loose windows are not cached.
  • #19 (overlapping_waits_charge_one_window) is wait accounting.
  • #33 (deduplication of repeated ranges) is refresh ranges per draw.

Tests

Two new tests in window_tests (7 passed). Release build of victory with --features diagnostics succeeds.

**@⁠wymd-wn118** on GitHub · 2026-11-25 22:28 UTC · [original](https://github.com/DexNom/VIctory/pull/55) `wymd-wn118:window-reuse-holds-the-ask` → `main` · +59 −1 · 1 files · 1 commits · closed without merging > **AI-generated and unverified.** Drafted by an AI agent (DeepSeek) from a single run of the title, with no human review. About 60 lines, one function, plus two tests. Judge whether to read on that basis. ## What A loose window is looked up by its `(start, len)` exactly, but the two kinds of ask make different lengths for the same memory: an ask without a length takes a tail of its 4 MiB cell (`tail_of`), one with a length takes the grid's window (`window_of`). An ask that found no window of its own then made a second one over memory another window already held, and that memory was copied once for each. `loose` now takes a window that begins at or below the ask, no lower than the ask's own line, and holds all of it. That is `holder_below`, split out from the map walk so it is tested without a card. ## Measured In the world, `VICTORY_WINDOW_TAILS=1 VICTORY_WINDOW_KB=256`, from the memory line (`the N MB of windows lie over M MB of title memory`): | | windows | title memory held | copied twice | |---|---|---|---| | before | 2,496 MB | 1,636 MB | 34-38% | | after | 1,499 MB | 1,198 MB | 17-20% | Repeat ratios sampled across a run, before: 864, 886, 999, 1,049, 953, 860 MB (34-38%). After: 226, 271, 301 MB (17-20%). **Limitation:** this is one title, one configuration, and the scene reached differs between runs. The window and cover numbers above are what moved; frame times alongside them are not comparable run to run. ## Not a duplicate Checked against all 53 open PRs: none changes the body of `loose()` or takes a window that holds an ask. - #46 and #53 (`cache registered shadow buffer lookups`) only *call* `loose` - they cache registered-buffer hits and state that loose windows are not cached. - #19 (`overlapping_waits_charge_one_window`) is wait accounting. - #33 (`deduplication of repeated ranges`) is refresh ranges per draw. ## Tests Two new tests in `window_tests` (7 passed). Release build of `victory` with `--features diagnostics` succeeds.
A loose window is looked up by its (start, len) exactly. The two kinds of
ask make different lengths for the same memory: an ask without a length
takes a tail of its 4 MiB cell (`tail_of`), one with a length takes the
grid's window (`window_of`). An ask that found no window of its own then
made a second one over memory another window already held, and that
memory was copied once for each.

Measured in the world (`VICTORY_WINDOW_TAILS=1 VICTORY_WINDOW_KB=256`):
2496 MB of windows lay over 1636 MB of title memory, so 34% of every
window's bytes were a copy of memory another window held. The memory line
now reads 1499 MB over 1198 MB (17-20%).

`loose` takes a window that begins at or below the ask, no lower than
the ask's own line, and holds all of it. That is `holder_below`, split
out from the map walk so it is tested without a card.

Drafted by an AI agent (DeepSeek) from a run of the title; measured, not
reviewed by a person.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:32:49 +00:00
Author
Owner

@⁠j-fuxa on GitHub · 2026-11-26 01:41 UTC · original

Cross-check of the window-copy numbers: how much of a loose window is touched

This is an independent measurement of the loose 4 MiB window scheme, from a different fork, to cross-check the table above. It was taken on an RTX 4060 Laptop 8 GB, 32 GB RAM, Windows 11, at world entry.

  • Host buffer copies were 2.8-3.0 GB. Of that, loose 4 MiB windows were 1.76-1.99 GB, but the submissions touched only 665-838 MiB of those window bytes.
  • The windows barely overlapped each other: 24-48 MiB.
  • The snapshot pool peaked at 1.2-1.3 GB out at once (in use).

The overlap here is far lower than the 34-38% in the "before" rows. The settings differ (this PR measures with VICTORY_WINDOW_TAILS=1 VICTORY_WINDOW_KB=256), so the numbers may not be comparable. In our run the larger saving was in the roughly half to two thirds of window bytes that no submission read, not in duplicates.

Suggestion. Add "bytes of each window touched by any submission" to the memory line, next to the windows-over-title-memory figure. If untouched bytes dominate on your setup, fetching windows by touched sub-range would save more than merging duplicates. If overlap dominates, this PR's approach is the right lever.

Caveats. Different code base and GPU. We did not vary window size or tail settings, and the scene reached differs from run to run.

**@⁠j-fuxa** on GitHub · 2026-11-26 01:41 UTC · [original](https://github.com/DexNom/VIctory/pull/55#issuecomment-7180025977) **Cross-check of the window-copy numbers: how much of a loose window is touched** This is an independent measurement of the loose 4 MiB window scheme, from a different fork, to cross-check the table above. It was taken on an RTX 4060 Laptop 8 GB, 32 GB RAM, Windows 11, at world entry. - Host buffer copies were 2.8-3.0 GB. Of that, loose 4 MiB windows were 1.76-1.99 GB, but the submissions touched only 665-838 MiB of those window bytes. - The windows barely overlapped each other: 24-48 MiB. - The snapshot pool peaked at 1.2-1.3 GB out at once (in use). The overlap here is far lower than the 34-38% in the "before" rows. The settings differ (this PR measures with `VICTORY_WINDOW_TAILS=1 VICTORY_WINDOW_KB=256`), so the numbers may not be comparable. In our run the larger saving was in the roughly half to two thirds of window bytes that no submission read, not in duplicates. **Suggestion.** Add "bytes of each window touched by any submission" to the memory line, next to the windows-over-title-memory figure. If untouched bytes dominate on your setup, fetching windows by touched sub-range would save more than merging duplicates. If overlap dominates, this PR's approach is the right lever. **Caveats.** Different code base and GPU. We did not vary window size or tail settings, and the scene reached differs from run to run.
github-bot closed this pull request 2026-11-26 05:25:19 +00:00
Author
Owner

@⁠wymd-wn118 on GitHub · 2026-11-26 04:50 UTC · original

Thanks for the cross-check - it changed our conclusion. This PR is not the main lever, and we are closing it.

Our setup

Windows 11, i7-14650HX, RTX 4060 Laptop 8 GB, 15.7 GB of physical memory (pagefile forced onto C: at 800 MB, so the box hits its ceiling early).

We reproduced your finding

Rerunning with the default window settings (no VICTORY_WINDOW_KB, no VICTORY_WINDOW_TAILS), the windows overlap 4-7%, consistent with your 24-48 MiB. So the 34-38% in the table above is not what the default configuration does - it is introduced by VICTORY_WINDOW_KB=256, which we had turned on to save memory on this machine.

configuration windows overlap
default 4 MiB 3,976 MB peak 4-7%
256 KiB + tails, without this PR 3,398 MB peak 34%
256 KiB + tails, with this PR 1,555 MB peak 24-27%

The touched-bytes figure you asked for

The project already tracks it: window_use() reports "MB of their pages ever copied" on the memory, what holds it: line. Measured here:

configuration windows bytes ever copied never read
default 4 MiB 3,668 MB 2,289 MB 38%
256 KiB + tails, without this PR 2,496 MB 1,568 MB 37%
256 KiB + tails, with this PR 1,325 MB 612 MB 54%

That is in the same place as your 665-838 MiB of 1.76-1.99 GB. You are right that untouched bytes dominate: 37-54% of window bytes are never copied, well above the 4-27% duplication. Fetching windows by touched sub-range is the better lever.

Why this PR is being closed

  • Standalone it does nothing. On the default grid the overlap is 4-7%, so there is nothing to save.
  • Paired with a smaller window it saves about 2.4 GB (3,976 -> 1,555 MB peak). That is real, but it does not fix this machine: VRAM still sits at 7,737 MB against a 7,189 MB budget, and the memory line records passes that made none for lack of room: 377.
  • An offline replay could not reproduce the saving at all (120-283 MB) because the addresses recorded in a log are the windows that survived, not the ones made and dropped. We mention it because it makes our original measurement weaker than it looked, not stronger.

One thing we suspect but have not proven

On this machine, character faces and some models sometimes load and sometimes do not. In the same runs the memory line records hundreds of refused host copies for lack of room, and the timings coincide. We have not isolated a cause, so treat this as a hypothesis only. If it is real, it points at the same place you do: window lifetime and the default window size under memory pressure, rather than deduplication.

Conclusion

Both datasets point the same way: window lifetime management and the default window size have more room than merging duplicates. Thanks again - this saved us from pushing a change that only pays off in a configuration we had chosen for our own machine's limits.

**@⁠wymd-wn118** on GitHub · 2026-11-26 04:50 UTC · [original](https://github.com/DexNom/VIctory/pull/55#issuecomment-7182946576) Thanks for the cross-check - it changed our conclusion. This PR is not the main lever, and we are closing it. ## Our setup Windows 11, i7-14650HX, **RTX 4060 Laptop 8 GB**, **15.7 GB** of physical memory (pagefile forced onto C: at 800 MB, so the box hits its ceiling early). ## We reproduced your finding Rerunning with the default window settings (no `VICTORY_WINDOW_KB`, no `VICTORY_WINDOW_TAILS`), the windows overlap **4-7%**, consistent with your 24-48 MiB. So the 34-38% in the table above is **not** what the default configuration does - it is introduced by `VICTORY_WINDOW_KB=256`, which we had turned on to save memory on this machine. | configuration | windows | overlap | |---|---|---| | default 4 MiB | 3,976 MB peak | 4-7% | | 256 KiB + tails, without this PR | 3,398 MB peak | 34% | | 256 KiB + tails, with this PR | 1,555 MB peak | 24-27% | ## The touched-bytes figure you asked for The project already tracks it: `window_use()` reports "MB of their pages ever copied" on the `memory, what holds it:` line. Measured here: | configuration | windows | bytes ever copied | never read | |---|---|---|---| | default 4 MiB | 3,668 MB | 2,289 MB | **38%** | | 256 KiB + tails, without this PR | 2,496 MB | 1,568 MB | **37%** | | 256 KiB + tails, with this PR | 1,325 MB | 612 MB | **54%** | That is in the same place as your 665-838 MiB of 1.76-1.99 GB. **You are right that untouched bytes dominate**: 37-54% of window bytes are never copied, well above the 4-27% duplication. Fetching windows by touched sub-range is the better lever. ## Why this PR is being closed - **Standalone it does nothing.** On the default grid the overlap is 4-7%, so there is nothing to save. - **Paired with a smaller window it saves about 2.4 GB** (3,976 -> 1,555 MB peak). That is real, but it does not fix this machine: VRAM still sits at 7,737 MB against a 7,189 MB budget, and the memory line records `passes that made none for lack of room: 377`. - **An offline replay could not reproduce the saving at all** (120-283 MB) because the addresses recorded in a log are the windows that survived, not the ones made and dropped. We mention it because it makes our original measurement weaker than it looked, not stronger. ## One thing we suspect but have not proven On this machine, character faces and some models sometimes load and sometimes do not. In the same runs the memory line records hundreds of refused host copies for lack of room, and the timings coincide. We have not isolated a cause, so treat this as a hypothesis only. If it is real, it points at the same place you do: window lifetime and the default window size under memory pressure, rather than deduplication. ## Conclusion Both datasets point the same way: **window lifetime management and the default window size have more room than merging duplicates.** Thanks again - this saved us from pushing a change that only pays off in a configuration we had chosen for our own machine's limits.
Author
Owner

@⁠wymd-wn118 on GitHub · 2026-11-26 04:50 UTC · original

Closing as agreed in the discussion above: on the default window grid the overlap is 4-7%, so this change only pays off together with a smaller window, and even then it does not relieve a 15.7 GB machine. Thank you both for the cross-check.

**@⁠wymd-wn118** on GitHub · 2026-11-26 04:50 UTC · [original](https://github.com/DexNom/VIctory/pull/55#issuecomment-7182948400) Closing as agreed in the discussion above: on the default window grid the overlap is 4-7%, so this change only pays off together with a smaller window, and even then it does not relieve a 15.7 GB machine. Thank you both for the cross-check.

Pull request closed

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