fix(host): the sync objects' table is compacted in place when few of its objects are live, so finalized objects cannot double it without end #2907

Merged
HumanBean merged 3 commits from HumanBean/Longshot:fix/sync-table-compact into main 2026-11-30 19:27:08 +00:00
Owner

Summary

A latent bug in the host's sync objects, found during a RAM/VRAM leak study on this PC. The game does not hit it in a
17-minute session
; it is fixed here for longer sessions and other access patterns, with log counters to see it.

Every guest mutex, event, semaphore or queue has a host object, found by its guest address in an open-addressing table
(host/nn_os_sync.c). A finalized object stays in its slot as a tombstone until another address takes the slot.
insert_locked made a new table twice the size every time half the slots were used, live objects and tombstones
alike, and kept the old table for the lookups that read it without the lock. Objects made and finalized at ever-new
addresses therefore doubled it without end: tests/test_obj_table_bounded.py, 3,000,000 such objects beside 3,000 live
ones, grows it to 4,194,304 slots and 743 MB on main.

What the game does (the new counters, a 10-minute tour): the table grows 2^16 → 2^20 slots while the first areas load,
with 131,067 of 131,072 used slots live at the 4th doubling and 194,551 of 262,144 at the 5th, then stays at 2^20 slots
for the rest of the tour, 0 compactions. The game keeps ~195k objects alive and finalizes few, so the table is sized by
them (~144-146 MB of the heap with the objects, in a jemalloc profile, on main and here alike).

Now a half-full table with under a quarter of its slots live is rehashed in place, at its size (compact_locked); it
grows when the live objects need it or the compaction allocation fails. A lookup without the lock that meets a slot emptied or refilled meanwhile either
finds its object (objects are never freed, and obj_is checks the identity) or misses, and the locked lookup answers a
miss, as it does for a slot changing today. HOS_SYNC_TABLE_COMPACT=0 doubles as before. The sync: object cache log
line (every 10 s) now also says the table's size, its live objects at the last resize and how often it grew or was
compacted, so a long session (the lab's) shows whether the path is ever taken.

Read first: insert_locked and compact_locked in host/nn_os_sync.c, tests/test_obj_table_bounded.py.

Testing

Tested: RTX 3090, NVIDIA 620.70.06, CachyOS Linux, 32 GB: four laps of Lost Woods → Zora's River → Hyrule Field →
Kakariko → Kokiri Forest (memtour.py, headless, the kokiri-start save, 40 s in each, ~13 min), on main and here;
every teleport and area played as on main, and the game quit cleanly.

  • tests/test_obj_table_bounded.py: the earlier fixture failed on main (the test commit alone), passed here, and failed with
    HOS_SYNC_TABLE_COMPACT=0. The updated fixture explicitly checks for growth with the switch off; its run is pending. test_obj_cache_size.py, test_obj_guest_id.py,
    test_multiwait_wake.py pass. test_multiwait_wake.py's list of calls that keep the core now has env_on_or (the
    switch's read: a getenv, as env_on already listed).
  • host/nn_os_sync.c checked with -fsyntax-only -Wall -Wextra with llvm-mingw (Windows) and clang (Linux): the same
    warnings as main, no new one; the game built (dev.py pack) and ran, its counters in the log line (the 10-minute
    tour in Measurements).
  • tests/run_all.py (all 916 checks): 767 passed, 37 failed, 112 skipped on this PC. All 37 also fail on a clean main
    checkout here (missing Vulkan/SPIR-V headers and other tools in this environment); none is new. CI runs the suite.

Still to test:

  • Lab PC (RX 580 8 GB, 16 GB RAM, Linux): a long session (an hour or more): the sync: object cache line's counters
    show whether the table ever compacts or grows past 2^20 slots (by hand).
  • Windows NVIDIA and AMD: a 20-minute play, expecting no change but the memory (@Beanstalk on this pull request).

Measurements

Verdict: a latent-bug fix, no change in the game: the compaction never runs in a 10-17 minute session (the game keeps
~195k objects alive), the sync objects' heap is the same on main and here, and fps is within the spread. The game-free
reproduction of the unbounded doubling is fixed.

Setup: RTX 3090, NVIDIA 620.70.06, CachyOS Linux, 32 GB. Game-free: tests/test_obj_table_bounded.py, 25 objects a frame
at new addresses for 120,000 frames beside 3,000 live ones. In game: memtour.py from the kokiri-start save (Lost Woods,
Zora's River, Hyrule Field, Kakariko, Kokiri Forest, laps), a jemalloc heap profile (LD_PRELOAD=libjemalloc.so.2,
MALLOC_CONF=prof:true) of each side, the new log counters on this side; fps by dev.py ab --scene hyrule-field (3
interleaved pairs, uncapped, 67 % render resolution, 1440p output).

Before: main @ 28cb22b9 After: this PR @ 32df2b83
table at most (slots), game-free 4,194,304 65,536
tables and object chunks at most, game-free 743 MB (381 MB at half time) 31.9 MB (31.9 MB at half time)
objects made, game-free 1,878,352 93,523
sync objects' heap (obj_lookup), game, jemalloc, ~10 min 89 → 146 MB, in steps (each a doubling during loads) 93 → 144 MB, then flat for the last 7 min
the table in game (new log line) (no line on main) 2^20 slots, 194,551 live at its last resize, 5 grown, 0 compacted
fps, Hyrule Field (each run) 140.0 / 150.7 / 150.2 (median 150.2) 150.0 / 149.2 / 149.4 (median 149.4), -0.5 %
1 % low fps (median) 115.6 (103.4 / 117.7 / 115.6) 109.3 (117.0 / 108.9 / 109.3), within the spread
median / p99 frame time 6.64 / 8.65 ms 6.64 / 9.15 ms
frames of 50 ms or more 0 0

The compaction never ran in these runs, so the frame-time rows compare the same code path; the 1 % low difference is
the runs' own spread (A1 103.4, B1 117.0).

Risks

  • A compaction takes table_lock exclusively and walks the table (65,536 slots by default), as a doubling did; it
    happens once every ~16,000 new addresses at most.
  • A lock-free lookup that runs during a compaction may miss and take the locked path (as when a slot changes today).
  • Off: HOS_SYNC_TABLE_COMPACT=0, or a revert. Nothing changes after updating: no files, settings or saves.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named). (37 fail here and on a clean main alike: this PC's missing headers and tools; see Testing)
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • Docs updated. (The switch's row and the code's comment: no reference page covers the table.)
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

It should also be checked on the lab (RX 580, 16 GB): a long session there shows, with the new counters, whether the path is ever taken.

🤖 Generated with Claude Code

https://claude.ai/code/session_016o1k1SdGuww9Q4o1mvYD9c

## Summary A latent bug in the host's sync objects, found during a RAM/VRAM leak study on this PC. **The game does not hit it in a 17-minute session**; it is fixed here for longer sessions and other access patterns, with log counters to see it. Every guest mutex, event, semaphore or queue has a host object, found by its guest address in an open-addressing table (`host/nn_os_sync.c`). A finalized object stays in its slot as a tombstone until another address takes the slot. `insert_locked` made a new table **twice the size** every time half the slots were used, live objects and tombstones alike, and kept the old table for the lookups that read it without the lock. Objects made and finalized at ever-new addresses therefore doubled it without end: `tests/test_obj_table_bounded.py`, 3,000,000 such objects beside 3,000 live ones, grows it to 4,194,304 slots and 743 MB on `main`. What the game does (the new counters, a 10-minute tour): the table grows 2^16 → 2^20 slots while the first areas load, with 131,067 of 131,072 used slots live at the 4th doubling and 194,551 of 262,144 at the 5th, then stays at 2^20 slots for the rest of the tour, 0 compactions. The game keeps ~195k objects alive and finalizes few, so the table is sized by them (~144-146 MB of the heap with the objects, in a jemalloc profile, on `main` and here alike). Now a half-full table with under a quarter of its slots live is rehashed **in place, at its size** (`compact_locked`); it grows when the live objects need it or the compaction allocation fails. A lookup without the lock that meets a slot emptied or refilled meanwhile either finds its object (objects are never freed, and `obj_is` checks the identity) or misses, and the locked lookup answers a miss, as it does for a slot changing today. `HOS_SYNC_TABLE_COMPACT=0` doubles as before. The `sync: object cache` log line (every 10 s) now also says the table's size, its live objects at the last resize and how often it grew or was compacted, so a long session (the lab's) shows whether the path is ever taken. Read first: `insert_locked` and `compact_locked` in `host/nn_os_sync.c`, `tests/test_obj_table_bounded.py`. ## Testing **Tested:** RTX 3090, NVIDIA 620.70.06, CachyOS Linux, 32 GB: four laps of Lost Woods → Zora's River → Hyrule Field → Kakariko → Kokiri Forest (`memtour.py`, headless, the `kokiri-start` save, 40 s in each, ~13 min), on `main` and here; every teleport and area played as on `main`, and the game quit cleanly. - `tests/test_obj_table_bounded.py`: the earlier fixture failed on `main` (the test commit alone), passed here, and failed with `HOS_SYNC_TABLE_COMPACT=0`. The updated fixture explicitly checks for growth with the switch off; its run is pending. `test_obj_cache_size.py`, `test_obj_guest_id.py`, `test_multiwait_wake.py` pass. `test_multiwait_wake.py`'s list of calls that keep the core now has `env_on_or` (the switch's read: a `getenv`, as `env_on` already listed). - `host/nn_os_sync.c` checked with `-fsyntax-only -Wall -Wextra` with llvm-mingw (Windows) and clang (Linux): the same warnings as `main`, no new one; the game built (`dev.py pack`) and ran, its counters in the log line (the 10-minute tour in Measurements). - `tests/run_all.py` (all 916 checks): 767 passed, 37 failed, 112 skipped on this PC. All 37 also fail on a clean `main` checkout here (missing Vulkan/SPIR-V headers and other tools in this environment); none is new. CI runs the suite. **Still to test:** - Lab PC (RX 580 8 GB, 16 GB RAM, Linux): a long session (an hour or more): the `sync: object cache` line's counters show whether the table ever compacts or grows past 2^20 slots (by hand). - Windows NVIDIA and AMD: a 20-minute play, expecting no change but the memory (`@Beanstalk` on this pull request). ## Measurements **Verdict:** a latent-bug fix, no change in the game: the compaction never runs in a 10-17 minute session (the game keeps ~195k objects alive), the sync objects' heap is the same on `main` and here, and fps is within the spread. The game-free reproduction of the unbounded doubling is fixed. Setup: RTX 3090, NVIDIA 620.70.06, CachyOS Linux, 32 GB. Game-free: `tests/test_obj_table_bounded.py`, 25 objects a frame at new addresses for 120,000 frames beside 3,000 live ones. In game: `memtour.py` from the `kokiri-start` save (Lost Woods, Zora's River, Hyrule Field, Kakariko, Kokiri Forest, laps), a jemalloc heap profile (`LD_PRELOAD=libjemalloc.so.2`, `MALLOC_CONF=prof:true`) of each side, the new log counters on this side; fps by `dev.py ab --scene hyrule-field` (3 interleaved pairs, uncapped, 67 % render resolution, 1440p output). | | Before: main @ 28cb22b9 | After: this PR @ 32df2b83 | |---|---|---| | table at most (slots), game-free | 4,194,304 | 65,536 | | tables and object chunks at most, game-free | 743 MB (381 MB at half time) | 31.9 MB (31.9 MB at half time) | | objects made, game-free | 1,878,352 | 93,523 | | sync objects' heap (`obj_lookup`), game, jemalloc, ~10 min | 89 → 146 MB, in steps (each a doubling during loads) | 93 → 144 MB, then flat for the last 7 min | | the table in game (new log line) | (no line on `main`) | 2^20 slots, 194,551 live at its last resize, 5 grown, 0 compacted | | fps, Hyrule Field (each run) | 140.0 / 150.7 / 150.2 (median 150.2) | 150.0 / 149.2 / 149.4 (median 149.4), -0.5 % | | 1 % low fps (median) | 115.6 (103.4 / 117.7 / 115.6) | 109.3 (117.0 / 108.9 / 109.3), within the spread | | median / p99 frame time | 6.64 / 8.65 ms | 6.64 / 9.15 ms | | frames of 50 ms or more | 0 | 0 | The compaction never ran in these runs, so the frame-time rows compare the same code path; the 1 % low difference is the runs' own spread (A1 103.4, B1 117.0). ## Risks - A compaction takes `table_lock` exclusively and walks the table (65,536 slots by default), as a doubling did; it happens once every ~16,000 new addresses at most. - A lock-free lookup that runs during a compaction may miss and take the locked path (as when a slot changes today). - Off: `HOS_SYNC_TABLE_COMPACT=0`, or a revert. Nothing changes after updating: no files, settings or saves. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). (37 fail here and on a clean `main` alike: this PC's missing headers and tools; see Testing) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] Docs updated. (The switch's row and the code's comment: no reference page covers the table.) - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. It should also be checked on the lab (RX 580, 16 GB): a long session there shows, with the new counters, whether the path is ever taken. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016o1k1SdGuww9Q4o1mvYD9c
Fails on main: 3,000,000 objects made and finalized at new addresses beside 3,000
live ones grow the table to 4,194,304 slots and 743 MB of tables and object chunks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016o1k1SdGuww9Q4o1mvYD9c
fix(host): the sync objects' table is compacted in place, so objects the game finalizes no longer grow it all session (HOS_SYNC_TABLE_COMPACT)
Some checks failed
PR description / Title and description (pull_request_target) Successful in 12s
CI / What the change needs (pull_request) Successful in 14s
CI / Third-party parts and guide screenshots (pull_request) Failing after 19s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 18s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 2m20s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 3m50s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 4m27s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 4m44s
CI / Website build and checks (pull_request) Failing after 37s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 18m50s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 33m44s
864f5dbf82
insert_locked doubled the table every time half its slots were used, live objects
and tombstones alike, and kept the old table for the lock-free readers. The game
makes and finalizes mutexes and events at new heap addresses all the time, so the
table, the objects a full table holds and the old tables grew for the whole
session: about 7 MB a minute in a memory tour on main.

A half-full table with under a quarter of its slots live is now rehashed where it
is, at its size. A lock-free reader sees a slot emptied or refilled meanwhile and
either finds its object (objects are never freed; obj_is checks the identity) or
misses, and the locked lookup answers. HOS_SYNC_TABLE_COMPACT=0 doubles as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016o1k1SdGuww9Q4o1mvYD9c
Author
Owner

Tested in game: RTX 3090 / NVIDIA 620.70.06 / Linux (CachyOS): four laps of Lost Woods, Zora's River, Hyrule Field, Kakariko and Kokiri Forest (memtour.py, headless, kokiri-start save, ~13 min); every area and teleport played as on main, clean quit.

Tested in game: RTX 3090 / NVIDIA 620.70.06 / Linux (CachyOS): four laps of Lost Woods, Zora's River, Hyrule Field, Kakariko and Kokiri Forest (memtour.py, headless, kokiri-start save, ~13 min); every area and teleport played as on main, clean quit.
Member

Possibly related, for context:

  • PR #1573 WIP: test(host): nn_os_sync.c compiled whole and driven from host threads — Open host sync-file test harness; may overlap test assumptions
Possibly related, for context: - PR #1573 WIP: test(host): nn_os_sync.c compiled whole and driven from host threads — Open host sync-file test harness; may overlap test assumptions
HumanBean force-pushed fix/sync-table-compact from 864f5dbf82
Some checks failed
PR description / Title and description (pull_request_target) Successful in 12s
CI / What the change needs (pull_request) Successful in 14s
CI / Third-party parts and guide screenshots (pull_request) Failing after 19s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 18s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 2m20s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 3m50s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 4m27s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 4m44s
CI / Website build and checks (pull_request) Failing after 37s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 18m50s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 33m44s
to 32df2b831b
Some checks failed
CI / Third-party parts and guide screenshots (pull_request) Failing after 16s
CI / What the change needs (pull_request) Successful in 32s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Failing after 18s
PR description / Title and description (pull_request_target) Successful in 10s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
2026-11-30 18:18:24 +00:00
Compare
HumanBean changed title from WIP: fix(host): the sync objects' table is compacted in place, so objects the game finalizes no longer grow it all session to WIP: fix(host): the sync objects' table is compacted in place when few of its objects are live, so finalized objects cannot double it without end 2026-11-30 18:38:49 +00:00
HumanBean force-pushed fix/sync-table-compact from 32df2b831b
Some checks failed
CI / Third-party parts and guide screenshots (pull_request) Failing after 16s
CI / What the change needs (pull_request) Successful in 32s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Failing after 18s
PR description / Title and description (pull_request_target) Successful in 10s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
to c750b78a66
Some checks failed
CI / Third-party parts and guide screenshots (pull_request) Failing after 14s
CI / What the change needs (pull_request) Successful in 32s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 18s
PR description / Title and description (pull_request_target) Successful in 7s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Failing after 36s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Failing after 35s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Failing after 42s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 32s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 37s
CI / Website build and checks (pull_request) Failing after 38s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 4m3s
2026-11-30 18:52:39 +00:00
Compare
Author
Owner

Rebased onto main @ ba3f14df (head c750b78a; was 32df2b83). Nothing on main since touches host/nn_os_sync.c, and the switches.def change there is elsewhere in the file, so the measurements still hold. After the rebase: test_obj_table_bounded, test_obj_cache_size, test_obj_guest_id and test_multiwait_wake pass. test_switch_table fails on main too (LONGSHOT_LAUNCHER_STARTUP has no row).

Rebased onto main @ ba3f14df (head c750b78a; was 32df2b83). Nothing on main since touches host/nn_os_sync.c, and the switches.def change there is elsewhere in the file, so the measurements still hold. After the rebase: test_obj_table_bounded, test_obj_cache_size, test_obj_guest_id and test_multiwait_wake pass. test_switch_table fails on main too (LONGSHOT_LAUNCHER_STARTUP has no row).
HumanBean changed title from WIP: fix(host): the sync objects' table is compacted in place when few of its objects are live, so finalized objects cannot double it without end to fix(host): the sync objects' table is compacted in place when few of its objects are live, so finalized objects cannot double it without end 2026-11-30 18:55:21 +00:00
BeanBot left a comment

Recommendation: Request changes. The synthetic churn test shows that compaction bounds table growth, but the game runs did not exercise compaction. Its effect on synchronization and frame pacing therefore remains unmeasured. (It stands on L3: The check CI / Third-party parts and guide screenshots (pull_request) fails on this head and passes on the base branch: Failing after 14s.)

The change reuses the sync-object table when tombstones dominate it, avoiding repeated doubling for sustained churn. It adds an exclusive table scan and rehash, plus a kill switch and diagnostic counters.

Blocking (1): must change before merging.

  1. L3: The check CI / Third-party parts and guide screenshots (pull_request) fails on this head and passes on the base branch: Failing after 14s.

Should fix (1): not blocking, but worth doing before merging.

  • L1 tests/test_obj_table_bounded.py:131: The switch-off run accepts any nonzero exit as proof that the old growth behavior occurred. (more on the line) Do: Make the switch-off case assert the expected growth explicitly and require a successful exit, or verify a distinct expected failure result.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L2 host/nn_os_sync.c:208: The runs do not measure a compaction while game threads are active. (more on the line) Do: Exercise compaction during a representative long game session and record its duration and frame times, including the requested Windows and AMD coverage. (@fix does its part first: Add timing for compaction and its lock hold so the run can identify the pause.)

@fix can do L1, L2 and L3.

Checks: Still running: 7 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes for the synthetic case: the reported 3 million-object churn run reaches 65,536 slots and 31.9 MB, versus 4,194,304 slots and 743 MB on main. The reported game runs had zero compactions, so they do not show an in-game memory or timing effect.

Other systems: The table serves guest synchronization across game threads on both Windows and Linux. Lock-free readers can encounter slots while they are cleared and refilled; misses fall back to the locked lookup. The reported Linux game runs did not exercise this path, and Windows and the longer AMD run remain outstanding.

Switches: HOS_SYNC_TABLE_COMPACT is added as a kill switch, on by default; =0 retains doubling. Its table row is present. The default fixes the synthetic churn case, but its timing when compaction occurs has not been measured in the game.

Reviewed: c750b78a66 against ba3f14dff1: Read AGENTS.md, CONTRIBUTING.md, the pull request template, relevant standards, the diff and commits, the changed table code and its lookup, insertion, finalization and cache callers, and the new test and its shared harness. Skimmed the rest of the large sync source, switch table and multiwait test. docs/review-checklist.md and the neighboring Tooling checkout were absent. The supplied comments and CI status were reviewed.; nothing run (a code review).

Checked and fine:

  • The new bounded-churn test clears the switches read by its fixture and tests that live objects remain findable after churn.
  • The switch is listed in switches.def, and both commits record AI assistance.
  • No game-derived or generated files are added by the diff.
  • A lock-free lookup that misses during compaction retries under the table lock.

Testing: Read-only review; no commands from the project, builds or tests were run. The supplied CI status includes one head-only failure, which the bot handles separately, and several checks still running.

Overlaps and merge order: Not checked; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, as HumanBean took it out of WIP. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The synthetic churn test shows that compaction bounds table growth, but the game runs did not exercise compaction. Its effect on synchronization and frame pacing therefore remains unmeasured. (It stands on L3: The check `CI / Third-party parts and guide screenshots (pull_request)` fails on this head and passes on the base branch: Failing after 14s.) The change reuses the sync-object table when tombstones dominate it, avoiding repeated doubling for sustained churn. It adds an exclusive table scan and rehash, plus a kill switch and diagnostic counters. **Blocking (1)**: must change before merging. 1. **L3**: The check `CI / Third-party parts and guide screenshots (pull_request)` fails on this head and passes on the base branch: Failing after 14s. **Should fix (1)**: not blocking, but worth doing before merging. - **L1** `tests/test_obj_table_bounded.py:131`: The switch-off run accepts any nonzero exit as proof that the old growth behavior occurred. (more on the line) **Do:** Make the switch-off case assert the expected growth explicitly and require a successful exit, or verify a distinct expected failure result. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L2** `host/nn_os_sync.c:208`: The runs do not measure a compaction while game threads are active. (more on the line) **Do:** Exercise compaction during a representative long game session and record its duration and frame times, including the requested Windows and AMD coverage. *(`@fix` does its part first: Add timing for compaction and its lock hold so the run can identify the pause.)* `@fix` can do L1, L2 and L3. **Checks:** Still running: 7 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes for the synthetic case: the reported 3 million-object churn run reaches 65,536 slots and 31.9 MB, versus 4,194,304 slots and 743 MB on main. The reported game runs had zero compactions, so they do not show an in-game memory or timing effect. **Other systems:** The table serves guest synchronization across game threads on both Windows and Linux. Lock-free readers can encounter slots while they are cleared and refilled; misses fall back to the locked lookup. The reported Linux game runs did not exercise this path, and Windows and the longer AMD run remain outstanding. **Switches:** HOS_SYNC_TABLE_COMPACT is added as a kill switch, on by default; =0 retains doubling. Its table row is present. The default fixes the synthetic churn case, but its timing when compaction occurs has not been measured in the game. **Reviewed:** c750b78a66f6 against ba3f14dff1a1: Read AGENTS.md, CONTRIBUTING.md, the pull request template, relevant standards, the diff and commits, the changed table code and its lookup, insertion, finalization and cache callers, and the new test and its shared harness. Skimmed the rest of the large sync source, switch table and multiwait test. docs/review-checklist.md and the neighboring Tooling checkout were absent. The supplied comments and CI status were reviewed.; nothing run (a code review). **Checked and fine:** - The new bounded-churn test clears the switches read by its fixture and tests that live objects remain findable after churn. - The switch is listed in switches.def, and both commits record AI assistance. - No game-derived or generated files are added by the diff. - A lock-free lookup that misses during compaction retries under the table lock. **Testing:** Read-only review; no commands from the project, builds or tests were run. The supplied CI status includes one head-only failure, which the bot handles separately, and several checks still running. **Overlaps and merge order:** Not checked; the network is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, as HumanBean took it out of WIP. Nothing was run; a maintainer decides.</sub>
@ -186,0 +205,4 @@
else __atomic_store_n(&table_log_grown, table_log_grown + 1, __ATOMIC_RELAXED);
}
static int compact_locked(void) { /* 1: the tombstones buried and the live objects put back, the size kept */
uint64_t live_n = 0;
Member

L2 (should fix): The runs do not measure a compaction while game threads are active.

When: When a long session reaches a half-used table with fewer than a quarter of its slots live, compaction scans and rebuilds the table while holding the exclusive lock; concurrent misses and insertions wait. The reported game runs performed zero compactions, so their frame times do not cover that pause.

Do: Exercise compaction during a representative long game session and record its duration and frame times, including the requested Windows and AMD coverage.

**L2** (should fix): The runs do not measure a compaction while game threads are active. *When:* When a long session reaches a half-used table with fewer than a quarter of its slots live, compaction scans and rebuilds the table while holding the exclusive lock; concurrent misses and insertions wait. The reported game runs performed zero compactions, so their frame times do not cover that pause. **Do:** Exercise compaction during a representative long game session and record its duration and frame times, including the requested Windows and AMD coverage.
@ -0,0 +128,4 @@
print("HOS_SYNC_TABLE_COMPACT=%s (as before: it should fail):" % compact)
r = subprocess.run([exe, mode], capture_output=True, text=True, env=env, timeout=600)
sys.stdout.write(r.stdout)
if bool(r.returncode) != bool(compact):
Member

L1 (should fix): The switch-off run accepts any nonzero exit as proof that the old growth behavior occurred.

When: If the switch-off fixture crashes, fails an earlier live-object assertion, or exits for another error, the test reports success without checking that the table grew as expected.

Do: Make the switch-off case assert the expected growth explicitly and require a successful exit, or verify a distinct expected failure result.

**L1** (should fix): The switch-off run accepts any nonzero exit as proof that the old growth behavior occurred. *When:* If the switch-off fixture crashes, fails an earlier live-object assertion, or exits for another error, the test reports success without checking that the table grew as expected. **Do:** Make the switch-off case assert the expected growth explicitly and require a successful exit, or verify a distinct expected failure result.
Author
Owner
@fix
fix(host): measure sync table compaction pauses
Some checks failed
PR description / Title and description (pull_request_target) Successful in 10s
CI / What the change needs (pull_request) Successful in 13s
CI / Third-party parts and guide screenshots (pull_request) Failing after 15s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 16s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Failing after 31s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Failing after 35s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Failing after 39s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 34s
CI / Website build and checks (pull_request) Failing after 31s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 39s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 4m7s
774882d7f1
As the review on #2907 asked.
BeanBot left a comment

Recommendation: Approve. The fix retains the table compaction and adds an explicit switch-off growth check. No defect was found in the changed lines. Recommend approval; not approved on the forge.

What @fix changed
I changed this pull request: the new head is 774882d7f1. I edited its description to match the change.

Changed

  • Switch-off fixture, tests/test_obj_table_bounded.py:71: The switch-off case explicitly checks table growth and requires a successful fixture exit. Tests were not run, as requested.

Changed in part (the rest is for the author)

  • Compaction timing, host/nn_os_sync.c:235: Added last and maximum compaction and exclusive-lock hold durations to the periodic log. The author must run a session with active game threads that triggers compaction and assess its pauses.

Left for the author

  • Guide screenshot check: Inspect the full check log for the three affected files and review the affected UI and guide. The supplied excerpt omits their names, so it does not establish which review records need changes.
  • Windows host compile check: Inspect the full checkout log and rerun the check; the excerpt reports Git exit 128 but omits its cause.
  • Linux renderer check: Inspect the full checkout log and rerun the check; the excerpt omits the failing command and its cause.
  • Windows renderer check: Inspect the full checkout log and rerun the check; the excerpt omits the failing command and its cause.
  • Game-free checks, part 1: Inspect the full checkout log and rerun the check; Git exited 128 before the tests, but the excerpt omits its cause.
  • Game-free checks, part 2: Inspect the full checkout log and rerun the check; Git exited 128 before the tests, but the excerpt omits its cause.
  • Website checks: Inspect the full checkout log and rerun the check; Git exited 128 before the build, but the excerpt omits its cause.

Nothing was built or run: the checks run again on the new head.

Compaction bounds table growth under sustained churn of finalized synchronization objects; the fix adds pause logging and strengthens the switch-off fixture. It adds timing calls on exclusive table lookups.

Checks: they run again on this head (CI / Third-party parts and guide screenshots (pull_request), CI / Host C for Windows (llvm-mingw, compile only) (pull_request), CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request), CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request), CI / Game-free checks (run_all.py, part 1/2) (pull_request) failed on the last one); a failure shows on the pull request.

Also noticed (4; not asked for, not blocking)
  • A session with active game threads that triggers compaction is still needed to assess the recorded pause.
  • The pull request also lists Windows play and a longer Linux session as still to test.
  • A session that triggers compaction would show the new timing counters and its effect on active game threads.
  • The updated switch-off fixture and CI have not yet run on this head.
More: does it help, other systems, switches, what was read

Does it help: Yes in the reported game-free reproduction: peak table size fell from 4,194,304 to 65,536 slots and large allocations from 743 MB to 31.9 MB. The reported game session did not trigger compaction, so its in-game pause cost remains unmeasured.

Other systems: The table serves host synchronization on Windows and Linux. The reported Linux game run completed cleanly; Windows play and a longer Linux session remain pending.

Switches: HOS_SYNC_TABLE_COMPACT defaults on and has a switches.def row; setting it to 0 restores doubling. The reported churn test supports the default, while active compaction pauses remain unmeasured.

Reviewed: 774882d7f1 against ba3f14dff1: Read the repository rules, PR template, diff, changed test and relevant table, lookup, logging and fixture code. Skimmed the remaining host implementation and test harness; the full changed code and switches.def were not read in full. The neighboring Tooling rules and docs/review-checklist.md were unavailable.; nothing run (a code review).

Checked and fine:

  • The switch-off fixture requires successful execution and verifies table growth.
  • The timing instrumentation preserves compaction and records both the last and maximum durations.
  • The description acknowledges the pending updated fixture run.

Testing: No commands that build or run project code were executed. The author reports the earlier fixture and Linux game run passed; CI has not run on this head.

Overlaps and merge order: Not checked; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The fix retains the table compaction and adds an explicit switch-off growth check. No defect was found in the changed lines. Recommend approval; not approved on the forge. **What `@fix` changed** I changed this pull request: the new head is 774882d7f1c6. I edited its description to match the change. **Changed** - **Switch-off fixture, tests/test_obj_table_bounded.py:71**: The switch-off case explicitly checks table growth and requires a successful fixture exit. Tests were not run, as requested. **Changed in part (the rest is for the author)** - **Compaction timing, host/nn_os_sync.c:235**: Added last and maximum compaction and exclusive-lock hold durations to the periodic log. The author must run a session with active game threads that triggers compaction and assess its pauses. **Left for the author** - **Guide screenshot check**: Inspect the full check log for the three affected files and review the affected UI and guide. The supplied excerpt omits their names, so it does not establish which review records need changes. - **Windows host compile check**: Inspect the full checkout log and rerun the check; the excerpt reports Git exit 128 but omits its cause. - **Linux renderer check**: Inspect the full checkout log and rerun the check; the excerpt omits the failing command and its cause. - **Windows renderer check**: Inspect the full checkout log and rerun the check; the excerpt omits the failing command and its cause. - **Game-free checks, part 1**: Inspect the full checkout log and rerun the check; Git exited 128 before the tests, but the excerpt omits its cause. - **Game-free checks, part 2**: Inspect the full checkout log and rerun the check; Git exited 128 before the tests, but the excerpt omits its cause. - **Website checks**: Inspect the full checkout log and rerun the check; Git exited 128 before the build, but the excerpt omits its cause. Nothing was built or run: the checks run again on the new head. Compaction bounds table growth under sustained churn of finalized synchronization objects; the fix adds pause logging and strengthens the switch-off fixture. It adds timing calls on exclusive table lookups. **Checks:** they run again on this head (`CI / Third-party parts and guide screenshots (pull_request)`, `CI / Host C for Windows (llvm-mingw, compile only) (pull_request)`, `CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request)`, `CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request)`, `CI / Game-free checks (run_all.py, part 1/2) (pull_request)` failed on the last one); a failure shows on the pull request. <details> <summary>Also noticed (4; not asked for, not blocking)</summary> - A session with active game threads that triggers compaction is still needed to assess the recorded pause. - The pull request also lists Windows play and a longer Linux session as still to test. - A session that triggers compaction would show the new timing counters and its effect on active game threads. - The updated switch-off fixture and CI have not yet run on this head. </details> <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes in the reported game-free reproduction: peak table size fell from 4,194,304 to 65,536 slots and large allocations from 743 MB to 31.9 MB. The reported game session did not trigger compaction, so its in-game pause cost remains unmeasured. **Other systems:** The table serves host synchronization on Windows and Linux. The reported Linux game run completed cleanly; Windows play and a longer Linux session remain pending. **Switches:** HOS_SYNC_TABLE_COMPACT defaults on and has a switches.def row; setting it to 0 restores doubling. The reported churn test supports the default, while active compaction pauses remain unmeasured. **Reviewed:** 774882d7f1c6 against ba3f14dff1a1: Read the repository rules, PR template, diff, changed test and relevant table, lookup, logging and fixture code. Skimmed the remaining host implementation and test harness; the full changed code and switches.def were not read in full. The neighboring Tooling rules and docs/review-checklist.md were unavailable.; nothing run (a code review). **Checked and fine:** - The switch-off fixture requires successful execution and verifies table growth. - The timing instrumentation preserves compaction and records both the last and maximum durations. - The description acknowledges the pending updated fixture run. **Testing:** No commands that build or run project code were executed. The author reports the earlier fixture and Linux game run passed; CI has not run on this head. **Overlaps and merge order:** Not checked; the network is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.</sub>
HumanBean deleted branch fix/sync-table-compact 2026-11-30 19:27:09 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
MagicBeanDev/Longshot!2907
No description provided.