perf(host): a larger, four-way cache for the sync object lookups (HOS_OBJ_CACHE, 16384 by default) #1781

Merged
HumanBean merged 3 commits from snaildev99/Longshot:perf/obj-cache into main 2026-11-20 16:17:49 +00:00
Contributor

Summary

Every time the game locks or unlocks one of its mutexes, Longshot has to find its own object for it. The small per-thread cache in front of that search (1,024 direct-mapped entries) missed at almost every step of one graphics routine's walk over a table of mutexes (f_80364080, the game's graphics front end, at a fixed 0x80 stride that the cache's hash folds onto few entries), so the slower shared-table search ran instead. docs/cpu-profile.md measures that search (obj_lookup) at 3.1 to 4.1 % of a core and the cache (obj) at 1.6 to 2.3 %. This PR makes that cache larger, 16,384 entries four ways a set with a mixing hash, so the walk fits in it: the cache then misses 0.7 % of 21 million lookups in the Market. HOS_OBJ_CACHE=<entries> sets another size, and HOS_OBJ_CACHE=0 keeps the fixed cache as before.

The goal is less work per lock and unlock for the same result. Frame rate is the check that nothing got slower; the effect is small but consistent: Castle Town's Market ran 2.0 % faster standing still and 2.5 % faster turning the camera on main a433db32 (three interleaved runs a side), and +1.5 % standing as the mean of eight on/off pairs in a 48-run matrix, a gain in every pair.

How: obj_cache_entries reads the switch (unset, empty or not a number: 16,384; 0: the fixed cache; else 256 to 65,536); obj_lookup_cached is made per thread at its first lookup (64-byte sets of four, murmur3's finalizer on the key, the oldest way replaced); a hit is validated exactly as the fixed cache's (the object's key and kind); obj_nockpt takes it when the switch is set; obj() adds the threads' counts up and logs sync: object cache (HOS_OBJ_CACHE=n a thread, k made): L lookups, M missed (p %) every 10 s. Nothing obj_nockpt reaches calls outside tests/test_multiwait_wake.py's allowlist (it runs under the multi-wait lock). Why the hash and the ways: with the fixed cache's multiply-and-shift, 16,384 direct-mapped entries still missed 1,880 of a 4,000-slot walk every pass; four ways with the mixing hash, 47.

Read first: host/nn_os_sync.c (obj_cache_entries, obj_lookup_cached, obj_nockpt); tests/test_obj_cache_size.py; the row in gpu/vk/switches.def.

See #1505 (the signal side of the same file), #1020 (where obj_lookup is lead 4).

Testing

Tested: Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X. In the game: this change at its pre-rebase head in a test tree on main a433db32 (test/perf-prs @ be5623e0 on my fork, built from scratch twice, 0 failed): 15 hands-free Market runs, 6 with HOS_OBJ_CACHE=16384 (0.69 % of 22 million lookups missed); in a v3.0.0 test tree, 24 Market runs with it (15 s standing, 40 s turning each, 36 caches made a run); before that two dozen hands-free runs in the Market and Hyrule Field with the first version on main 544229a2. No hang, no FATAL and no frame of 50 ms or more in any log. The rebase onto main 068fb8eb (#1802) changed no code: only docs/development.md, which #1802 removed, lost the switch's row (its row in gpu/vk/switches.def is the reference now). The default went to 16,384 in 2361252d (the row a tune switch, the test run unset, =0 and =256): the code paths are the ones measured, only which is the default changed. Rebased onto main 89c3d21e (7f55fbe2): one line of gpu/vk/switches.def met #1814's new HOS_OCB_HOLD_MS row, both rows kept; the PR's diff is otherwise the same line for line. At 7f55fbe2 the tests that read host/nn_os_sync.c (13), tests/test_switch_table.py and tests/test_env_on.py pass, but for tests/test_tracy_funcs.py, which fails on main 89c3d21e alike (it reads Linux objects). Game-free at 2361252d: tests/test_obj_cache_size.py (compiles the real table, the cache, obj_nockpt and the flush: the value's parsing; the walk unset (47 of 4,000 slots miss its last pass), at =0 and at =256 (all 4,000 miss); 200,000 lookups among objects buried, re-kinded and reused, compared with the table; the log line) tests/test_multiwait_wake.py, the other checks that read nn_os_sync.c, tests/test_switch_table.py and tests/test_env_on.py pass. tests/run_all.py on Windows at 2361252d: 708 passed, 47 failed, 116 skipped; main 068fb8eb on this PC: 704 passed, 50 failed, 116 skipped. No failure that main does not have: main's, apart from timing tests that failed in one run only and pass when run alone (test_invalidate_vcore, test_compile_stops_on_exception, test_longshot_ctl, test_mesh_args_cleanup); test_vbytes times out at 600 s in both. Main's failures on this PC: test_appimage_player_build, test_auto_handheld, test_bug_report_defaults, test_capture_read_once, test_crash_dialog, test_crt_options, test_damage_debug_menu, test_dev_ab, test_dev_build, test_dev_migrate, test_dev_packs, test_display_startup_failure, test_dlss_feature_size, test_failed_compile_keeps_objects, test_frame_overlap, test_frame_wait_bounds, test_game_menu_mouse_buttons, test_guest_imported, test_high_fps_fixes, test_host_guest_writes, test_hud_layout_row, test_job_queue, test_libc_hooks, test_lift_cache, test_linux_preflight, test_linux_pressure, test_make_game_ngx, test_mise_build, test_missing_nup, test_mods_list, test_ngx_sdk, test_pads_after_menu, test_pending_guest_import, test_pipeline_play_cache, test_portable_builder_home, test_portable_builder_startup, test_prepare_cache_save, test_present_thread, test_profiling_mode, test_psychov35_fsr3_fg, test_readback_timeout_source, test_sdiv_overflow, test_seed_reader, test_slow_frames, test_song_note_cue, test_upscaler_rows, test_vcore_escape, test_walk_key.

Still to test:

  • Linux, any GPU: the Market for a few minutes, main against this PR; the game's CPU seconds with the frame rate capped at 60 on a PC that holds 60 there, and the frame times uncapped, expecting the same frame rate or better with less CPU time, no hang, and a sync: object cache line with a miss rate under a few percent (@Beanstalk linux, reporting that line).
  • Scenes with more threads or mutexes than the Market (Kakariko, a boss fight), expecting the miss rate to stay under a few percent (by hand).

Measurements

Verdict: less work per lock and unlock: 0.7 % of lookups miss the cache and fall through to the shared table. Frame rate is the check that nothing got slower: the Market +2.0 % standing and +2.5 % turning on main a433db32; in the matrix +1.5 % standing (a gain in every pair, +0.3 to +1.7 fps) and +0.7 % turning (inside the runs' spread). No change in memory beyond the runs' spread. Nothing in Hyrule Field, where the renderer sets the frame.

Baseline: one executable on both sides, the test tree test/perf-prs @ be5623e0 on my fork (main a433db32 with this PR and its siblings #1780 and #1782 merged, the default hot list, A64_VECFP=0 so the lifted code is main's). Before is every switch unset, which then ran main's code path (the switch was opt-in when measured; with this PR's default the same two sides are HOS_OBJ_CACHE=0 and unset); After sets only this one. Main has since moved ten commits, to 89c3d21e. The first four (#1802 docs, tools and the PR template; #1774 and #1807 the Insert menu's rows; #1792 dev packs) change, outside comments, docs and the dev tools, the Insert menu's code and the version string and some log texts. The six after them are other performance work (#1843 ASTC re-encoding, #1814 HOS_OCB_HOLD_MS, #1158 VRAM given back, #1848 capture buffers, #1782 the lift's float paths) and a CI change (#1850). None touches host/nn_os_sync.c or the lookups it makes, and each runs alike on both sides of an A/B that changes only this cache. They may move the Market's frame rate as a whole, so the percentages above are a433db32's; the farm request measures on current main.
Setup: Windows 11 (build 22631), GeForce RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X (12 cores), 128 GB. Child Link at the Market's save point by day; 3840x2160 full screen, frame rate cap Uncapped, no mods; the GPU wait 0.0 to 0.1 ms in every run (the processor sets the frame). Hands-free through scripts/longshot_ctl.py: the save loads, 10 s to settle, 15 s standing (the FPS counter's value once a second), then 40 s with the right stick held to one side. Three runs a side, interleaved, the median.

Before: test/perf-prs @ be5623e0, every switch unset After, HOS_OBJ_CACHE=16384: test/perf-prs @ be5623e0 Δ
Market standing, fps (the three runs) 68.8 (68.9, 68.8, 68.2) 70.2 (69.5, 70.2, 70.2) +2.0 %
Market turning, fps (the three runs) 63.0 (63.0, 63.5, 62.8) 64.6 (63.8, 64.7, 64.6) +2.5 %

With its two siblings on as well, the same runs: 76.0 standing (+10.5 %) and 68.1 turning (+8.1 %). No hang, no FATAL and no frame of 50 ms or more in any of the 15 logs.

sync: object cache (HOS_OBJ_CACHE=16384 a thread, 36 made): 20766382 lookups, 143515 missed (0.69 %)
sync: object cache (HOS_OBJ_CACHE=16384 a thread, 36 made): 22164823 lookups, 147833 missed (0.67 %)

The 48-run matrix

The change was measured beside every combination of #1780, #1782 and main's RX_VK_CAPTURE_NT, in one test tree test/perf-matrix @ 2c30c326 on my fork (v3.0.0 09cbdd97 with the three changes, every lifted file at -O2 so that the hot list is not a variable, built with A64_VECFP=0 and on). Sixteen variants, three interleaved runs each, 48 runs in 74 minutes with nobody at the PC. Before and After are the same executable; only this switch differs.

what else was on Before, unset: standing / turning fps After, HOS_OBJ_CACHE=16384 Δ standing Δ turning
nothing 68.5 / 63.5 69.6 / 63.9 +1.6 % +0.6 %
RX_VK_CAPTURE_NT=1 69.7 / 63.7 70.0 / 63.8 +0.4 % +0.2 %
HOS_NVN_REC_HANDOFF=1 71.2 / 64.5 72.3 / 65.4 +1.5 % +1.4 %
both of those 72.0 / 65.5 73.1 / 65.8 +1.5 % +0.5 %
the float paths 71.5 / 65.7 72.0 / 66.5 +0.7 % +1.2 %
the float paths, RX_VK_CAPTURE_NT=1 71.2 / 65.6 72.8 / 66.5 +2.2 % +1.4 %
the float paths, HOS_NVN_REC_HANDOFF=1 74.2 / 67.1 75.9 / 66.6 +2.3 % -0.7 %
all three 75.0 / 67.7 76.2 / 68.2 +1.6 % +0.7 %

The gain is about the size of the spread in any one pair, and shows as a gain because all eight pairs agree. Peak working set, unset against set: 9,944 to 10,030 MB either way. The run file is docs/tested/2026-11-19-obj-cache-snaildev99-matrix-o.md.

Offline (not a frame rate; the table sits in this process's caches, so a miss is cheap here): a walk of 4,000 mutexes at a 0x80 stride among 60,000 objects: misses a pass 4,000 (fixed cache) to 47 (16,384 entries); 17.4 to 7.4 ns a lookup.

The switch

HOS_OBJ_CACHE (new, run time, a tune switch): entries of each thread's cache of sync objects (256 to 65,536, a power of two). 16,384 by default, as the measurements chose (the Market +2.0 % standing, a gain in every pair of the matrix, 0.7 % of lookups missed); HOS_OBJ_CACHE=0 is the fixed 1,024-entry cache, main's path.

Risks

What could break: a stale hit would lock the wrong object (a hang, or a race far away); a hit is checked exactly as the fixed cache's is (objects are never freed, only reused, and each hit checks key and kind). Memory: entries x 16 bytes for each thread that makes sync lookups, never freed when a thread ends: 256 KB a thread at 16,384, 36 threads in the Market, about 9 MB; not visible in the working set above.

Turning it off: HOS_OBJ_CACHE=0 (in the environment or longshot_env.txt): the fixed cache, as on main; HOS_NO_OBJ_CACHE still turns both caches off.

After updating: each game thread that locks has a 256 KB cache (about 9 MB in the Market); saves, longshot_options.ini and the caches do not change.

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).
  • 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 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. (tests/test_obj_cache_size.py, new; tests/test_multiwait_wake.py and the other checks that read nn_os_sync.c pass unchanged; tests/test_switch_table.py reads the new row.)
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows: built and played; Linux not built.)
  • Docs updated.
  • 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.

🤖 Generated with Claude Code

## Summary Every time the game locks or unlocks one of its mutexes, Longshot has to find its own object for it. The small per-thread cache in front of that search (1,024 direct-mapped entries) missed at almost every step of one graphics routine's walk over a table of mutexes (`f_80364080`, the game's graphics front end, at a fixed 0x80 stride that the cache's hash folds onto few entries), so the slower shared-table search ran instead. `docs/cpu-profile.md` measures that search (`obj_lookup`) at 3.1 to 4.1 % of a core and the cache (`obj`) at 1.6 to 2.3 %. This PR makes that cache larger, 16,384 entries four ways a set with a mixing hash, so the walk fits in it: the cache then misses 0.7 % of 21 million lookups in the Market. `HOS_OBJ_CACHE=<entries>` sets another size, and `HOS_OBJ_CACHE=0` keeps the fixed cache as before. The goal is less work per lock and unlock for the same result. Frame rate is the check that nothing got slower; the effect is small but consistent: Castle Town's Market ran 2.0 % faster standing still and 2.5 % faster turning the camera on main a433db32 (three interleaved runs a side), and +1.5 % standing as the mean of eight on/off pairs in a 48-run matrix, a gain in every pair. How: `obj_cache_entries` reads the switch (unset, empty or not a number: 16,384; `0`: the fixed cache; else 256 to 65,536); `obj_lookup_cached` is made per thread at its first lookup (64-byte sets of four, murmur3's finalizer on the key, the oldest way replaced); a hit is validated exactly as the fixed cache's (the object's key and kind); `obj_nockpt` takes it when the switch is set; `obj()` adds the threads' counts up and logs `sync: object cache (HOS_OBJ_CACHE=n a thread, k made): L lookups, M missed (p %)` every 10 s. Nothing `obj_nockpt` reaches calls outside `tests/test_multiwait_wake.py`'s allowlist (it runs under the multi-wait lock). Why the hash and the ways: with the fixed cache's multiply-and-shift, 16,384 direct-mapped entries still missed 1,880 of a 4,000-slot walk every pass; four ways with the mixing hash, 47. Read first: `host/nn_os_sync.c` (`obj_cache_entries`, `obj_lookup_cached`, `obj_nockpt`); `tests/test_obj_cache_size.py`; the row in `gpu/vk/switches.def`. See #1505 (the signal side of the same file), #1020 (where `obj_lookup` is lead 4). ## Testing **Tested:** Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X. In the game: this change at its pre-rebase head in a test tree on main a433db32 (`test/perf-prs` @ be5623e0 on my fork, built from scratch twice, 0 failed): 15 hands-free Market runs, 6 with `HOS_OBJ_CACHE=16384` (0.69 % of 22 million lookups missed); in a v3.0.0 test tree, 24 Market runs with it (15 s standing, 40 s turning each, 36 caches made a run); before that two dozen hands-free runs in the Market and Hyrule Field with the first version on main 544229a2. No hang, no `FATAL` and no frame of 50 ms or more in any log. The rebase onto main 068fb8eb (#1802) changed no code: only `docs/development.md`, which #1802 removed, lost the switch's row (its row in `gpu/vk/switches.def` is the reference now). The default went to 16,384 in 2361252d (the row a `tune` switch, the test run unset, `=0` and `=256`): the code paths are the ones measured, only which is the default changed. Rebased onto main 89c3d21e (7f55fbe2): one line of `gpu/vk/switches.def` met #1814's new `HOS_OCB_HOLD_MS` row, both rows kept; the PR's diff is otherwise the same line for line. At 7f55fbe2 the tests that read `host/nn_os_sync.c` (13), `tests/test_switch_table.py` and `tests/test_env_on.py` pass, but for `tests/test_tracy_funcs.py`, which fails on main 89c3d21e alike (it reads Linux objects). Game-free at 2361252d: `tests/test_obj_cache_size.py` (compiles the real table, the cache, `obj_nockpt` and the flush: the value's parsing; the walk unset (47 of 4,000 slots miss its last pass), at `=0` and at `=256` (all 4,000 miss); 200,000 lookups among objects buried, re-kinded and reused, compared with the table; the log line) `tests/test_multiwait_wake.py`, the other checks that read `nn_os_sync.c`, `tests/test_switch_table.py` and `tests/test_env_on.py` pass. `tests/run_all.py` on Windows at 2361252d: 708 passed, 47 failed, 116 skipped; main 068fb8eb on this PC: 704 passed, 50 failed, 116 skipped. No failure that main does not have: main's, apart from timing tests that failed in one run only and pass when run alone (`test_invalidate_vcore`, `test_compile_stops_on_exception`, `test_longshot_ctl`, `test_mesh_args_cleanup`); `test_vbytes` times out at 600 s in both. Main's failures on this PC: `test_appimage_player_build`, `test_auto_handheld`, `test_bug_report_defaults`, `test_capture_read_once`, `test_crash_dialog`, `test_crt_options`, `test_damage_debug_menu`, `test_dev_ab`, `test_dev_build`, `test_dev_migrate`, `test_dev_packs`, `test_display_startup_failure`, `test_dlss_feature_size`, `test_failed_compile_keeps_objects`, `test_frame_overlap`, `test_frame_wait_bounds`, `test_game_menu_mouse_buttons`, `test_guest_imported`, `test_high_fps_fixes`, `test_host_guest_writes`, `test_hud_layout_row`, `test_job_queue`, `test_libc_hooks`, `test_lift_cache`, `test_linux_preflight`, `test_linux_pressure`, `test_make_game_ngx`, `test_mise_build`, `test_missing_nup`, `test_mods_list`, `test_ngx_sdk`, `test_pads_after_menu`, `test_pending_guest_import`, `test_pipeline_play_cache`, `test_portable_builder_home`, `test_portable_builder_startup`, `test_prepare_cache_save`, `test_present_thread`, `test_profiling_mode`, `test_psychov35_fsr3_fg`, `test_readback_timeout_source`, `test_sdiv_overflow`, `test_seed_reader`, `test_slow_frames`, `test_song_note_cue`, `test_upscaler_rows`, `test_vcore_escape`, `test_walk_key`. **Still to test:** - Linux, any GPU: the Market for a few minutes, main against this PR; the game's CPU seconds with the frame rate capped at 60 on a PC that holds 60 there, and the frame times uncapped, expecting the same frame rate or better with less CPU time, no hang, and a `sync: object cache` line with a miss rate under a few percent (@Beanstalk linux, reporting that line). - Scenes with more threads or mutexes than the Market (Kakariko, a boss fight), expecting the miss rate to stay under a few percent (by hand). ## Measurements **Verdict:** less work per lock and unlock: 0.7 % of lookups miss the cache and fall through to the shared table. Frame rate is the check that nothing got slower: the Market +2.0 % standing and +2.5 % turning on main a433db32; in the matrix +1.5 % standing (a gain in every pair, +0.3 to +1.7 fps) and +0.7 % turning (inside the runs' spread). No change in memory beyond the runs' spread. Nothing in Hyrule Field, where the renderer sets the frame. Baseline: one executable on both sides, the test tree `test/perf-prs` @ be5623e0 on my fork (main a433db32 with this PR and its siblings #1780 and #1782 merged, the default hot list, `A64_VECFP=0` so the lifted code is main's). Before is every switch unset, which then ran main's code path (the switch was opt-in when measured; with this PR's default the same two sides are `HOS_OBJ_CACHE=0` and unset); After sets only this one. Main has since moved ten commits, to 89c3d21e. The first four (#1802 docs, tools and the PR template; #1774 and #1807 the Insert menu's rows; #1792 dev packs) change, outside comments, docs and the dev tools, the Insert menu's code and the version string and some log texts. The six after them are other performance work (#1843 ASTC re-encoding, #1814 `HOS_OCB_HOLD_MS`, #1158 VRAM given back, #1848 capture buffers, #1782 the lift's float paths) and a CI change (#1850). None touches `host/nn_os_sync.c` or the lookups it makes, and each runs alike on both sides of an A/B that changes only this cache. They may move the Market's frame rate as a whole, so the percentages above are a433db32's; the farm request measures on current main. Setup: Windows 11 (build 22631), GeForce RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X (12 cores), 128 GB. Child Link at the Market's save point by day; 3840x2160 full screen, frame rate cap Uncapped, no mods; the GPU wait 0.0 to 0.1 ms in every run (the processor sets the frame). Hands-free through `scripts/longshot_ctl.py`: the save loads, 10 s to settle, 15 s standing (the FPS counter's value once a second), then 40 s with the right stick held to one side. Three runs a side, interleaved, the median. | | Before: test/perf-prs @ be5623e0, every switch unset | After, `HOS_OBJ_CACHE=16384`: test/perf-prs @ be5623e0 | Δ | |---|---|---|---| | Market standing, fps (the three runs) | 68.8 (68.9, 68.8, 68.2) | 70.2 (69.5, 70.2, 70.2) | +2.0 % | | Market turning, fps (the three runs) | 63.0 (63.0, 63.5, 62.8) | 64.6 (63.8, 64.7, 64.6) | +2.5 % | With its two siblings on as well, the same runs: 76.0 standing (+10.5 %) and 68.1 turning (+8.1 %). No hang, no `FATAL` and no frame of 50 ms or more in any of the 15 logs. ``` sync: object cache (HOS_OBJ_CACHE=16384 a thread, 36 made): 20766382 lookups, 143515 missed (0.69 %) sync: object cache (HOS_OBJ_CACHE=16384 a thread, 36 made): 22164823 lookups, 147833 missed (0.67 %) ``` ### The 48-run matrix The change was measured beside every combination of #1780, #1782 and main's `RX_VK_CAPTURE_NT`, in one test tree `test/perf-matrix` @ 2c30c326 on my fork (v3.0.0 09cbdd97 with the three changes, every lifted file at -O2 so that the hot list is not a variable, built with `A64_VECFP=0` and on). Sixteen variants, three interleaved runs each, 48 runs in 74 minutes with nobody at the PC. Before and After are the same executable; only this switch differs. | what else was on | Before, unset: standing / turning fps | After, `HOS_OBJ_CACHE=16384` | Δ standing | Δ turning | |---|---|---|---|---| | nothing | 68.5 / 63.5 | 69.6 / 63.9 | +1.6 % | +0.6 % | | `RX_VK_CAPTURE_NT=1` | 69.7 / 63.7 | 70.0 / 63.8 | +0.4 % | +0.2 % | | `HOS_NVN_REC_HANDOFF=1` | 71.2 / 64.5 | 72.3 / 65.4 | +1.5 % | +1.4 % | | both of those | 72.0 / 65.5 | 73.1 / 65.8 | +1.5 % | +0.5 % | | the float paths | 71.5 / 65.7 | 72.0 / 66.5 | +0.7 % | +1.2 % | | the float paths, `RX_VK_CAPTURE_NT=1` | 71.2 / 65.6 | 72.8 / 66.5 | +2.2 % | +1.4 % | | the float paths, `HOS_NVN_REC_HANDOFF=1` | 74.2 / 67.1 | 75.9 / 66.6 | +2.3 % | -0.7 % | | all three | 75.0 / 67.7 | 76.2 / 68.2 | +1.6 % | +0.7 % | The gain is about the size of the spread in any one pair, and shows as a gain because all eight pairs agree. Peak working set, unset against set: 9,944 to 10,030 MB either way. The run file is `docs/tested/2026-11-19-obj-cache-snaildev99-matrix-o.md`. Offline (not a frame rate; the table sits in this process's caches, so a miss is cheap here): a walk of 4,000 mutexes at a 0x80 stride among 60,000 objects: misses a pass 4,000 (fixed cache) to 47 (16,384 entries); 17.4 to 7.4 ns a lookup. ### The switch `HOS_OBJ_CACHE` (new, run time, a `tune` switch): entries of each thread's cache of sync objects (256 to 65,536, a power of two). 16,384 by default, as the measurements chose (the Market +2.0 % standing, a gain in every pair of the matrix, 0.7 % of lookups missed); `HOS_OBJ_CACHE=0` is the fixed 1,024-entry cache, main's path. ## Risks **What could break:** a stale hit would lock the wrong object (a hang, or a race far away); a hit is checked exactly as the fixed cache's is (objects are never freed, only reused, and each hit checks key and kind). Memory: entries x 16 bytes for each thread that makes sync lookups, never freed when a thread ends: 256 KB a thread at 16,384, 36 threads in the Market, about 9 MB; not visible in the working set above. **Turning it off:** `HOS_OBJ_CACHE=0` (in the environment or `longshot_env.txt`): the fixed cache, as on main; `HOS_NO_OBJ_CACHE` still turns both caches off. **After updating:** each game thread that locks has a 256 KB cache (about 9 MB in the Market); saves, `longshot_options.ini` and the caches do not change. ## 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). - [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 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. (`tests/test_obj_cache_size.py`, new; `tests/test_multiwait_wake.py` and the other checks that read `nn_os_sync.c` pass unchanged; `tests/test_switch_table.py` reads the new row.) - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows: built and played; Linux not built.) - [x] Docs updated. - [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. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Every nn::os call finds the host object of its guest mutex, event or queue through a per-thread cache
of 1024 direct-mapped entries in front of the shared table. In a timed profile of the Market,
obj_lookup was 2 % of the main thread's samples, 0.4 ms a frame (RTX 3090, Ryzen 9 5900X), and 253 of
its 276 samples came from one game function, f_80364080 under the graphics front end's record pass:
it searches a table whose every slot has its own mutex, locking and unlocking each slot it passes, so
a search over more slots than the cache holds misses at every step (about 80 % of that function's
time on the main thread was obj_lookup).

HOS_OBJ_CACHE=<entries> gives each thread a cache of that many entries (256 to 65536, a power of two),
made on the heap at its first lookup, four ways a set in one 64-byte line, the oldest way replaced and
the set picked by murmur3's finalizer: with the fixed cache's multiply-and-shift, even 16384 entries
missed 1,880 of a 4,000-slot walk at a 0x80 stride on every pass; four-way with the mixing hash, 47.
Its counts stay the thread's own on the lookup path (it runs under mw_lock in WaitAny's scan); obj()
adds them up and logs "sync: object cache ..." every 10 s. Unset, the cache is main's; obj() reads
one flag that stays 0.

tests/test_obj_cache_size.py compiles the real table, the cache and obj_nockpt: the switch's parsing,
the walk with the fixed cache (every lookup misses), 16384 (under 2 %) and 256 (misses: the size is
honoured), 200,000 lookups among objects buried, re-kinded and reused compared with the table itself,
and the log line. --bench (not a frame rate; everything in this process's caches, where a miss is
cheap): 17.4 ns a lookup with the fixed cache, 7.4 with 16384 entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
docs(tested): the object cache's Market matrix run
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 7s
beanstalk/approval waiting for a BigBean's 👍 on the request
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
f49be7cbe8
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Author
Contributor

Tested in game: Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X: 24 hands-free runs in the child Market with HOS_OBJ_CACHE=16384 (15 s standing, then 40 s turning the camera), in a test build of v3.0.0 with this change (test/perf-matrix @ 2c30c326 on my fork). 36 caches made a run, 0.67 to 0.69 % of about 21 million lookups missed, no hang, no FATAL and no frame of 50 ms or more in any log; +0.3 to +1.7 fps standing in all eight on/off pairs. Not built or played at this head on current main yet: that is why this is WIP.

Tested in game: Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X: 24 hands-free runs in the child Market with HOS_OBJ_CACHE=16384 (15 s standing, then 40 s turning the camera), in a test build of v3.0.0 with this change (test/perf-matrix @ 2c30c326 on my fork). 36 caches made a run, 0.67 to 0.69 % of about 21 million lookups missed, no hang, no FATAL and no frame of 50 ms or more in any log; +0.3 to +1.7 fps standing in all eight on/off pairs. Not built or played at this head on current main yet: that is why this is WIP.
Member

Possibly related, for context:

  • PR #1573 WIP: test(host): nn_os_sync.c compiled whole and driven from host threads — Open test PR exercises the same nn_os_sync.c sync core
Possibly related, for context: - PR #1573 WIP: test(host): nn_os_sync.c compiled whole and driven from host threads — Open test PR exercises the same nn_os_sync.c sync core
Author
Contributor

Built and played at this head. The test tree is test/perf-prs @ be5623e0 on my fork: main a433db32 with #1780, #1781 and #1782 merged, the default hot list, built from scratch twice (A64_VECFP=0, where the lifted code is main's, and the float paths on). Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X, 3840x2160 uncapped, the child Market: 15 s standing, then 40 s turning the camera; five variants, three interleaved runs each, nobody at the PC, medians.

standing fps (the three runs) turning fps (the three runs) standing turning
nothing on 68.8 (68.9, 68.8, 68.2) 63.0 (63.0, 63.5, 62.8)
HOS_NVN_REC_HANDOFF=1 (#1780) 71.8 (71.8, 72.0, 71.2) 65.6 (65.1, 65.9, 65.6) +4.4 % +4.1 %
HOS_OBJ_CACHE=16384 (#1781) 70.2 (69.5, 70.2, 70.2) 64.6 (63.8, 64.7, 64.6) +2.0 % +2.5 %
the float paths (#1782) 71.2 (70.5, 71.2, 72.3) 66.2 (65.2, 66.2, 66.3) +3.5 % +5.1 %
all three 76.0 (75.9, 76.1, 76.0) 68.1 (68.1, 68.4, 68.0) +10.5 % +8.1 %

No frame of 50 ms or more, no FATAL and no not a live recording in any of the 15 logs; the object cache missed 0.69 % of 22 million lookups.

Build cost of the float paths on a default build (both from scratch, 23 jobs): the lifted files' compiler time 7,374 s to 7,646 s (+3.7 %), the compile's wall time 458 s to 422 s (the slowest hot piece sets it, and it is not slower), lifted objects 679 to 687 MB.

The description has these numbers; the full 16-variant matrix on v3.0.0 is still its first table.

Built and played at this head. The test tree is `test/perf-prs` @ be5623e0 on my fork: main a433db32 with #1780, #1781 and #1782 merged, the default hot list, built from scratch twice (`A64_VECFP=0`, where the lifted code is main's, and the float paths on). Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X, 3840x2160 uncapped, the child Market: 15 s standing, then 40 s turning the camera; five variants, three interleaved runs each, nobody at the PC, medians. | | standing fps (the three runs) | turning fps (the three runs) | standing | turning | |---|---|---|---|---| | nothing on | 68.8 (68.9, 68.8, 68.2) | 63.0 (63.0, 63.5, 62.8) | | | | `HOS_NVN_REC_HANDOFF=1` (#1780) | 71.8 (71.8, 72.0, 71.2) | 65.6 (65.1, 65.9, 65.6) | +4.4 % | +4.1 % | | `HOS_OBJ_CACHE=16384` (#1781) | 70.2 (69.5, 70.2, 70.2) | 64.6 (63.8, 64.7, 64.6) | +2.0 % | +2.5 % | | the float paths (#1782) | 71.2 (70.5, 71.2, 72.3) | 66.2 (65.2, 66.2, 66.3) | +3.5 % | +5.1 % | | all three | 76.0 (75.9, 76.1, 76.0) | 68.1 (68.1, 68.4, 68.0) | +10.5 % | +8.1 % | No frame of 50 ms or more, no `FATAL` and no `not a live recording` in any of the 15 logs; the object cache missed 0.69 % of 22 million lookups. Build cost of the float paths on a default build (both from scratch, 23 jobs): the lifted files' compiler time 7,374 s to 7,646 s (+3.7 %), the compile's wall time 458 s to 422 s (the slowest hot piece sets it, and it is not slower), lifted objects 679 to 687 MB. The description has these numbers; the full 16-variant matrix on v3.0.0 is still its first table.
Author
Contributor

@Beanstalk linux: build this branch and play a few minutes in the Market with HOS_OBJ_CACHE=16384 set, expecting no hang and a "sync: object cache" log line with a miss rate under a few percent. This is the one box left before ready: the host code has only been built on Windows.

@Beanstalk linux: build this branch and play a few minutes in the Market with HOS_OBJ_CACHE=16384 set, expecting no hang and a "sync: object cache" log line with a miss rate under a few percent. This is the one box left before ready: the host code has only been built on Windows.
Member

@snaildev99 only members of BigBeans can start the farm.

One of them can approve this request by reacting 👍 to it or to this comment. This request was for f49be7c, and the PR has changed since (458a68b), so a 👍 no longer approves it. Comment @Beanstalk again to ask for the new commit.

@snaildev99 only members of `BigBeans` can start the farm. ~~One of them can approve this request by reacting 👍 to it or to this comment.~~ This request was for `f49be7c`, and the PR has changed since (`458a68b`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
snaildev99 force-pushed perf/obj-cache from f49be7cbe8
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 7s
beanstalk/approval waiting for a BigBean's 👍 on the request
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to 458a68bc79
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 7s
beanstalk/approval waiting for a BigBean's 👍 on the request
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
2026-11-20 00:48:10 +00:00
Compare
Author
Contributor

Rebased onto main 068fb8eb (458a68bc). #1802 removed docs/development.md, which held this switch's row; its row in gpu/vk/switches.def is the reference now, so that edit is dropped and no code changed. The description now uses the new template, and says plainly what this PR is for: less work on the game's threads (far fewer searches of the shared table on each lock and unlock), with frame rate as the check that nothing got slower.

Why the numbers still hold on 068fb8eb: they were measured on main a433db32, and the four commits since (#1802 docs, tools and the PR template; #1774 and #1807 the Insert menu's rows; #1792 dev packs): outside comments, docs and the dev tools they change the Insert menu's code (#1774, #1807) and the version string and some log texts (#1802): nothing in host/nn_os_sync.c, and nothing the Market runs each frame but the FPS counter's overlay, which runs alike on both sides. So the numbers hold.

The farm request is reworded below, to measure the game's CPU time at a frame cap besides the frame times. A ~2 % change is close to what two runs a side can resolve, and the point of the change is less CPU time for the same frames.

Rebased onto main 068fb8eb (458a68bc). #1802 removed `docs/development.md`, which held this switch's row; its row in `gpu/vk/switches.def` is the reference now, so that edit is dropped and no code changed. The description now uses the new template, and says plainly what this PR is for: less work on the game's threads (far fewer searches of the shared table on each lock and unlock), with frame rate as the check that nothing got slower. Why the numbers still hold on 068fb8eb: they were measured on main a433db32, and the four commits since (#1802 docs, tools and the PR template; #1774 and #1807 the Insert menu's rows; #1792 dev packs): outside comments, docs and the dev tools they change the Insert menu's code (#1774, #1807) and the version string and some log texts (#1802): nothing in `host/nn_os_sync.c`, and nothing the Market runs each frame but the FPS counter's overlay, which runs alike on both sides. So the numbers hold. The farm request is reworded below, to measure the game's CPU time at a frame cap besides the frame times. A ~2 % change is close to what two runs a side can resolve, and the point of the change is less CPU time for the same frames.
Author
Contributor

@Beanstalk linux: the Market for a few minutes, HOS_OBJ_CACHE=16384 against unset. Measure the game's CPU seconds with the frame rate capped at 60 (on a PC that holds 60 there), and the frame times uncapped. Expect the same frame rate or better with less CPU time, no hang, and a "sync: object cache" log line with a miss rate under a few percent; report that line.

@Beanstalk linux: the Market for a few minutes, HOS_OBJ_CACHE=16384 against unset. Measure the game's CPU seconds with the frame rate capped at 60 (on a PC that holds 60 there), and the frame times uncapped. Expect the same frame rate or better with less CPU time, no hang, and a "sync: object cache" log line with a miss rate under a few percent; report that line.
Member

@snaildev99 only members of BigBeans can start the farm.

One of them can approve this request by reacting 👍 to it or to this comment. This request was for 458a68b, and the PR has changed since (2361252), so a 👍 no longer approves it. Comment @Beanstalk again to ask for the new commit.

@snaildev99 only members of `BigBeans` can start the farm. ~~One of them can approve this request by reacting 👍 to it or to this comment.~~ This request was for `458a68b`, and the PR has changed since (`2361252`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
perf(host): the four-way object cache on by default at 16384 entries; HOS_OBJ_CACHE=0 is the fixed cache
Some checks reported errors
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 14s
beanstalk/approval approved by HumanBean (reviewed)
beanstalk/linux 0/1 pass, 2 error
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
2361252d03
The measurements chose 16384 (the Market +2.0 % standing on main a433db32, a gain in all
eight pairs of the matrix, 0.7 % of lookups missed), and a switch ships at the value its
measurements chose (docs/dev/standards.md, "Switches"). Unset, empty or not a number:
16384; 0: the fixed 1024-entry cache, as before; HOS_NO_OBJ_CACHE still turns both off.
The row becomes a tune switch; tests/test_obj_cache_size.py checks unset, =0 and =256.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
snaildev99 changed title from WIP: perf(host): a larger, four-way cache for the sync object lookups (HOS_OBJ_CACHE, opt-in) to WIP: perf(host): a larger, four-way cache for the sync object lookups (HOS_OBJ_CACHE, 16384 by default) 2026-11-20 01:39:01 +00:00
Author
Contributor

The object cache is now 16,384 entries by default (2361252d): docs/dev/standards.md says a switch ships at the value its measurements chose, and never off just because it is new or unmeasured, and the measurements here choose 16,384 (the Market +2.0 % standing on main a433db32, a gain in all eight pairs of the matrix, 0.7 % of lookups missed). HOS_OBJ_CACHE=0 is the fixed 1,024-entry cache, main's path; another number sets another size; HOS_NO_OBJ_CACHE still turns both off. The row is now a tune switch, and tests/test_obj_cache_size.py checks unset, =0 and =256. Only the default changed: both code paths are the ones measured. The Linux run below is now main against this PR.

The object cache is now 16,384 entries by default (2361252d): docs/dev/standards.md says a switch ships at the value its measurements chose, and never off just because it is new or unmeasured, and the measurements here choose 16,384 (the Market +2.0 % standing on main a433db32, a gain in all eight pairs of the matrix, 0.7 % of lookups missed). `HOS_OBJ_CACHE=0` is the fixed 1,024-entry cache, main's path; another number sets another size; `HOS_NO_OBJ_CACHE` still turns both off. The row is now a `tune` switch, and `tests/test_obj_cache_size.py` checks unset, `=0` and `=256`. Only the default changed: both code paths are the ones measured. The Linux run below is now main against this PR.
Author
Contributor

@Beanstalk linux: main against this PR in the Market for a few minutes (the 16384-entry cache is the default now). Measure the game's CPU seconds with the frame rate capped at 60 (on a PC that holds 60 there), and the frame times uncapped. Expect the same frame rate or better with less CPU time, no hang, and a "sync: object cache" log line with a miss rate under a few percent; report that line.

@Beanstalk linux: main against this PR in the Market for a few minutes (the 16384-entry cache is the default now). Measure the game's CPU seconds with the frame rate capped at 60 (on a PC that holds 60 there), and the frame times uncapped. Expect the same frame rate or better with less CPU time, no hang, and a "sync: object cache" log line with a miss rate under a few percent; report that line.
Member

@snaildev99 only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@snaildev99 only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Owner

@Beanstalk

@Beanstalk
Member
Beanstalk test farm · an earlier run: commit 2361252 (the newer results are in a comment below)

Commit 2361252 · tier reviewed · approved by HumanBean · dashboard

What will be tested · AI plan (gpt-6.1-terra)

On Linux, compare main and the PR in the child Market, with a 60 FPS cap and uncapped to expose CPU and frame-time effects. The run takes about 22 minutes per tester and records CPU seconds, FPS, frame times, memory, and the cache miss-rate log. Crashes, missing cache logs, a settled miss rate above 3%, or substantial performance regressions fail the plan; the capped FPS check also verifies that the test PC holds approximately 60 FPS.

  • Where: linux (1-2 reports).
  • Matrix: 2 cells, each on main and the PR: frame_rate_cap 0 or 6.
  • market: from the repository's save kokiri-start (settings vsync=2, frame_generation=0), then teleport to Market, measure market for 40 s (after 15 s warm-up); 2 runs on each side for each of 2 cells (1 game start a run).
  • Measured: crashes, frame times, stutters and hitches, draws and frame rate, memory and CPU time, the game's log, numbers from the game's log.
  • The PR fails if: CPU time is more than 10% above main; or it crashes; or frame rate is more than 5% below main; or frame rate is below 55; or peak memory is more than 15% above main; or value_miss_pct is above 3; or frame time (p99) is more than 10% above main; or forbidden log lines is above 0; or expected log lines missing is above 0.
  • Time: about 28 min of game runs per tester (4 game starts), plus the two builds.

Done (started 08:11 UTC). Comment @Beanstalk to run it again.

Target Reports Crash Frame p99 (ms) vs main VRAM peak (MB) vs main Result
linux 0/1 — — — error
Scenario · matrix cell Target Frame p99 (ms) vs main Result
market · frame_rate_cap=0 linux — —
market · frame_rate_cap=6 linux — —
<!-- beanstalk:previous --> <details><summary>Beanstalk test farm · an earlier run: commit <code>2361252</code> (the newer results are in a comment below)</summary> Commit `2361252` · tier **reviewed** · approved by HumanBean · [dashboard](https://beanstalk.magicbean.dev/prs/1781) **What will be tested** · AI plan (`gpt-6.1-terra`) On Linux, compare main and the PR in the child Market, with a 60 FPS cap and uncapped to expose CPU and frame-time effects. The run takes about 22 minutes per tester and records CPU seconds, FPS, frame times, memory, and the cache miss-rate log. Crashes, missing cache logs, a settled miss rate above 3%, or substantial performance regressions fail the plan; the capped FPS check also verifies that the test PC holds approximately 60 FPS. - **Where:** linux (1-2 reports). - **Matrix:** 2 cells, each on main and the PR: frame_rate_cap `0` or `6`. - **market:** from the repository's save `kokiri-start` (settings vsync=2, frame_generation=0), then teleport to Market, measure market for 40 s (after 15 s warm-up); 2 runs on each side for each of 2 cells (1 game start a run). - **Measured:** crashes, frame times, stutters and hitches, draws and frame rate, memory and CPU time, the game's log, numbers from the game's log. - **The PR fails if:** CPU time is more than 10% above main; or it crashes; or frame rate is more than 5% below main; or frame rate is below 55; or peak memory is more than 15% above main; or value_miss_pct is above 3; or frame time (p99) is more than 10% above main; or forbidden log lines is above 0; or expected log lines missing is above 0. - **Time:** about 28 min of game runs per tester (4 game starts), plus the two builds. Done (started 08:11 UTC). Comment `@Beanstalk` to run it again. | Target | Reports | Crash | Frame p99 (ms) vs main | VRAM peak (MB) vs main | Result | | --- | --- | --- | --- | --- | --- | | linux | 0/1 | — | — | — | error | | Scenario · matrix cell | Target | Frame p99 (ms) vs main | Result | | --- | --- | --- | --- | | market · `frame_rate_cap=0` | linux | — | — | | market · `frame_rate_cap=6` | linux | — | — | </details>
HumanBean added this to the WIP project 2026-11-20 08:11:28 +00:00
snaildev99 force-pushed perf/obj-cache from 2361252d03
Some checks reported errors
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 14s
beanstalk/approval approved by HumanBean (reviewed)
beanstalk/linux 0/1 pass, 2 error
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to 7f55fbe26b
Some checks failed
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Failing after 18s
beanstalk/approval changed since the request: ask again
2026-11-20 10:28:55 +00:00
Compare
Member

Beanstalk test farm

Commit 7f55fbe · approved by nobody yet · dashboard

A member of BigBeans can review this commit and comment @Beanstalk to test it.

<!-- beanstalk:sticky --> ### Beanstalk test farm Commit `7f55fbe` · approved by nobody yet · [dashboard](https://beanstalk.magicbean.dev/prs/1781) A member of `BigBeans` can review this commit and comment `@Beanstalk` to test it.
Author
Contributor

Rebased onto main 89c3d21e (7f55fbe2). #1814 added HOS_OCB_HOLD_MS on the line of gpu/vk/switches.def where this PR's row goes, so the PR no longer merged; both rows are kept, ours first, and the rest of the diff is the same line for line. The tests that read host/nn_os_sync.c, the switch table and env_on pass at the new head (test_tracy_funcs fails on main alike: it reads Linux objects).

Rebased onto main 89c3d21e (7f55fbe2). #1814 added `HOS_OCB_HOLD_MS` on the line of `gpu/vk/switches.def` where this PR's row goes, so the PR no longer merged; both rows are kept, ours first, and the rest of the diff is the same line for line. The tests that read `host/nn_os_sync.c`, the switch table and `env_on` pass at the new head (`test_tracy_funcs` fails on main alike: it reads Linux objects).
HumanBean changed title from WIP: perf(host): a larger, four-way cache for the sync object lookups (HOS_OBJ_CACHE, 16384 by default) to perf(host): a larger, four-way cache for the sync object lookups (HOS_OBJ_CACHE, 16384 by default) 2026-11-20 16:17:11 +00:00
HumanBean deleted branch perf/obj-cache 2026-11-20 16:17:50 +00:00
Contributor

Data on the same lookup from a different approach, in case it helps this PR. HeyListen 86d68f05 (Sacrappy/HeyListen, GPL-3.0) skips the search for mutexes altogether. It stores the host object's number in the guest nn::os::MutexType's nesting-count word (+8), which this layer never uses, and takes it only while that object is still the address's mutex. A copied or cleared mutex falls back to the normal lookup and gets a new number. That covers exactly the f_80364080 slot walk you describe (one different mutex per slot).

On an RX 9070 XT / Ryzen 7 5800X (Linux, RADV), with our build on main @ 89c3d21e and the port on by default: hf48run uncapped, 2 interleaved runs a side. HOS_NO_MUTEX_IX=1 (the lookup as on main) gives 79.9 / 81.0 fps against 82.3 / 83.1 with it on (run_a medians), about +3 %. Every other change in that build measured within noise of it in the same battery. I haven't measured it together with HOS_OBJ_CACHE, so I can't say whether the two add up or cover each other.

Your PR owns the lookup, so I'm not opening a competing one. If you want the index as a commit on top of this, or as a separate small PR afterwards, say so and I'll send it with a main-vs-PR run.

Data on the same lookup from a different approach, in case it helps this PR. HeyListen 86d68f05 (Sacrappy/HeyListen, GPL-3.0) skips the search for mutexes altogether. It stores the host object's number in the guest `nn::os::MutexType`'s nesting-count word (+8), which this layer never uses, and takes it only while that object is still the address's mutex. A copied or cleared mutex falls back to the normal lookup and gets a new number. That covers exactly the `f_80364080` slot walk you describe (one different mutex per slot). On an RX 9070 XT / Ryzen 7 5800X (Linux, RADV), with our build on `main` @ `89c3d21e` and the port on by default: `hf48run` uncapped, 2 interleaved runs a side. `HOS_NO_MUTEX_IX=1` (the lookup as on `main`) gives 79.9 / 81.0 fps against 82.3 / 83.1 with it on (run_a medians), about +3 %. Every other change in that build measured within noise of it in the same battery. I haven't measured it together with `HOS_OBJ_CACHE`, so I can't say whether the two add up or cover each other. Your PR owns the lookup, so I'm not opening a competing one. If you want the index as a commit on top of this, or as a separate small PR afterwards, say so and I'll send it with a main-vs-PR run.
Author
Contributor

Thanks, that's a good lead, and the slot walk is the right target. #1781 was merged a few hours ago (2210931c), so a separate small PR on current main is the clean way; I'd be glad to see it, with HeyListen credited.

Two things would help it:

  • The gain over current main, where HOS_OBJ_CACHE (16384) is on by default and answers about 99.3 % of the Market's lookups, so much of the walk's cost is already gone there. Your +3 % was against 89c3d21e, before the cache. Main against main plus the index, and the same pair with HOS_OBJ_CACHE=0 on both sides, would show how much each adds.
  • That nothing else reads the word at +8. Longshot's mutex HLE never writes the guest MutexType today, so whatever game or SDK code reads there sees what the game wrote. A note that no lifted code loads a MutexType's +8 outside the nn::os imports would settle it.
Thanks, that's a good lead, and the slot walk is the right target. #1781 was merged a few hours ago (2210931c), so a separate small PR on current main is the clean way; I'd be glad to see it, with HeyListen credited. Two things would help it: - The gain over current main, where `HOS_OBJ_CACHE` (16384) is on by default and answers about 99.3 % of the Market's lookups, so much of the walk's cost is already gone there. Your +3 % was against 89c3d21e, before the cache. Main against main plus the index, and the same pair with `HOS_OBJ_CACHE=0` on both sides, would show how much each adds. - That nothing else reads the word at +8. Longshot's mutex HLE never writes the guest `MutexType` today, so whatever game or SDK code reads there sees what the game wrote. A note that no lifted code loads a `MutexType`'s +8 outside the `nn::os` imports would settle it.
Some checks failed
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Failing after 18s
beanstalk/approval changed since the request: ask again
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
5 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!1781
No description provided.