perf(host): FreeAddressRegion gives its virtual core up while the region's pages are discarded #1646

Merged
HumanBean merged 6 commits from Jiro113/Longshot:perf/vcore-improvements into main 2026-11-20 17:28:35 +00:00
Contributor

Type: perf · Risk: low · Tested on: Windows 11, RTX 4090 · Needs: Linux, any GPU

TL;DR

When the game frees a large block of memory, the runtime hands its pages back to the system, for milliseconds, and the
freeing thread kept its virtual core throughout, holding up the game's threads waiting for it. Now it gives the core
up for that work. Against current main, in 3 runs a side in Castle Town's market, frames are the same (within the
spread); waits for a core of 50 ms or more fell from 287 to 19 (medians). On an older main (c507b98c) the change took
away waits of 300 ms or more and raised the 1 % low from 29 to 35 fps; main no longer has those waits.

Breakdown

  • Who it helps: on current main, nothing a player sees in the market's frame rate (Measurements); the game's
    loader threads wait less for a core there. On main c507b98c, anyone walking around the market (hitches).
  • What was wrong: the game's resource memory thread kept its virtual core while the runtime handed a freed
    region's pages back to the system, so the game's threads on that core were held up for the whole of it.
  • What changes: the freeing thread gives its virtual core up while the pages are handed back, and takes one again
    after; the region stays reserved until its pages are handed back.
  • What does not change: what is freed and when, the hand-back itself (HOS_KEEP_FREED_PAGES as before), saves,
    options and caches.
  • How it was checked: 3 runs a side in the south market against main 868f6be8, interleaved after a warm-up of each
    (medians): frames within the spread (mean frame time 18.39 against 18.54 ms, 1 % low 24.3 against 23.8 fps, the
    same-seed pairs going either way); windows with a wait for a core of 300 ms or more, none on either side; waits of 50
    ms or more for a core, every thread's, 287 on main, 19 here. A game-free test fails on main for the bug's reason and
    passes here. The rebased tree ran in the game: the four runs of this PR in the series (a warm-up and three measured,
    300 s each in the market), no error or hang.
  • What is still open: Linux builds the whole game from the rebased tree (Ubuntu 22.04 under WSL) and ran in the game
    before the rebase (GrimVisage's comment, an RX 9070 XT); Intel GPUs and the Steam Deck are not run.
  • Risk: low: one more host task gives the core up, as a file read does, once for each region freed; the region's
    bookkeeping keeps it from being handed out again during the hand-back. The freeing thread then waits to take a core
    back, the kind of wait #1632 found freezing loads on an Arc iGPU for a decode that gave its core up at every call;
    on main since #1339 that is no new wait, as the renderer's import check before the hand-back already takes one back
    for each region freed. In every run of both series, on both sides, that thread never waited 50 ms or more for a core,
    but once (124 ms, in a load before the market, in the first series) (Risks).

Why

In Castle Town's market, walking in its south part, the vcores: log line shows game threads waiting for a virtual
core; on main c507b98c (the first series here) they waited 0.3 to 0.9 s, and the frame rate dipped in hitches. Most of
those long waits were for core 1. The game's resource memory thread (Resource Memory, pinned to core 1) frees memory
regions as it streams resources there; each free hands the region's pages back to the system (DiscardVirtualMemory
on Windows, MADV_REMOVE on Linux), milliseconds for a large region, and the thread kept core 1 throughout. The game's
core-1 job workers (ModuleSystemWorker1, BaseProcExecutor1, NavMeshCAStepDepWorker1), of a higher priority than
the freeing thread, could not have the core until it was done, and the main thread waited for them to finish their
jobs. A profiled run on main c507b98c put most of the resource memory thread's extra work in slow frames into that
hand-back, with core 1 held.

See #1150 (merged): it keeps the core for an invalidate that has nothing to wait for, where giving it up cost more than
it saved; this is the other side, a host task long enough that keeping the core holds up the game. See #327 (open: mask
0 and the guest's core cache) and #249 (closed: named threads first) for the other work on the virtual cores: neither
touches this path. See #1553 (merged): it gives the core up around the recording diagnostics and large decodes, for
waits of the same kind in the market; both series here are on a main that has it. See #1543 (merged): its Tracy zones
found a market frame's main thread spending about 10 of 18.6 ms in one job-loop wait. See #1503: the virtual-core gate
lets a low-priority thread wait up to a second for a core (HOS_VCORE_STARVE_US); this PR does not change the gate,
it takes away the host work that kept core 1 busy. See #1542 (open): one of its commits makes taking and giving up a
core cheaper (part of #1503); it doesn't touch host/hos_mem.c and keeps hos_vcore_away/hos_vcore_back, so the two
merge in either order. See #1632 (merged; on main in the second series): on an Arc iGPU, loads froze while the native
zstd decode, which gave its core up around every call, waited to take one back; the decode now keeps its core. This PR
gives the core up once for each region freed, for milliseconds of work; Risks has the waits measured. See #1020: its
leads find the market's frame waiting on the main thread, which waits on its job workers.

See #1610: hos_region_free took the region off the list before handing its pages back, so an allocation meanwhile
could be given pages about to be wiped. Once the hand-back no longer holds the core, the window is wider, so this PR
does what #1610 proposes in its items 1 to 3: the region stays listed, marked as being freed, until its pages are
handed back, and a second free of it meanwhile does nothing (item 4 is #432's).

See #1339 (merged; on main in the second series): before the hand-back, the runtime now asks the renderer, on Windows
too (Linux already did), whether it imported the pages, and zeroes imported pages in place instead of handing them
back. Asking gives the core up and takes one back, once for each region freed. With this PR the thread gives its core
up before the question and takes one back once, after the hand-back or the zeroing: the question's own give-up does
nothing for a thread that holds no core. On main the hand-back itself still runs with the core held. Main no longer has
the market's waits of 300 ms or more (Measurements); which of the changes merged since c507b98c took them away is not
established.

Players' logs with the same waits: #1436 (Windows, rc.7, an i5-12400 with 6 cores) has 31 vcores: lines with a wait of
300 ms or more for a core, 23 of them after it reaches the market, many at the one-second limit; #996 (Linux, rc.4) has
waits of 0.5 to 1 s in the market in 9 of its 196 vcores: lines. Both are older than #1339 and #1576; whether current
main still has those waits on those PCs, and whether this PR changes them there, is not measured. #597 (rough frame
times in the market on a Ryzen 7 9800X3D) has no log yet. See #1576 (merged; on main in the second series): it makes
the game's own work a frame cheaper in the same market. The two touch different files.

What changed

hos_region_free (nn::os::FreeAddressRegion) used to take the region off its list, then hand its pages back with the
thread's virtual core held. Now it gives the core up for the hand-back, as a file read does, and takes the region off
the list only once the hand-back is done, so a region allocated meanwhile cannot be given pages that are being handed
back.

  • host: hos_region_free in host/hos_mem.c: under the lock, finds the region, marks it as being freed and marks its
    pages; lets the lock go, hos_vcore_away(), discard_pages(); then removes the region under the lock and
    hos_vcore_back() if the thread had a core. An address that is no region, or a region already being freed, returns
    at once, keeping the core. A region being freed stays in the list, so hos_region_alloc skips it and the control
    bridge's range checks (hos_mem_region, hos_regions) still read it as mapped; hos_region_alloc writes its new
    entry unmarked. The comments in hos_region_free and hos_mem_region say why only its own hos_vcore_back takes a
    core back, and that a region being freed still reads as mapped.
  • tests: tests/test_vcore_region_free.py compiles the actual hos_region_free and hos_region_alloc with stand-ins
    and checks that the hand-back runs once, without the core and outside the lock, with the region still listed; that
    the region then leaves the list with the others kept in order and the core taken back once; that an unknown address
    keeps the core and a thread holding no core takes none; that a second free of the region during its hand-back does
    nothing and leaves it listed; that a region of no size leaves the list; and that a region allocated while another
    is being freed can itself be freed. On main 7 of its checks fail: "the discard runs without the virtual core", "the
    region stays listed through its discard (no allocation is handed its pages)", "the core is held again after it,
    taken once, and the lock let go", "an allocation while the region is discarded is not handed its pages (#1610)",
    "after the discard the region allocated meanwhile stays listed and the freed one is gone", "a second free of the
    region while it is discarded leaves it listed (its address is not handed out again yet)" and "after both frees the
    core is held again, taken once, and the lock let go".
  • tests: tests/test_host_free_marks.py (from #1339) compiles host/hos_mem.c with stand-ins of its own, which since
    the rebase have to include hos_vcore_away and hos_vcore_back; its fixture now stands in for them, counting the
    cores given up, and checks after each region free that every core given up was taken back. Its other checks are
    unchanged.

Measurements

Verdict: no change in frames against current main. On main 868f6be8 every frame row is within the spread (mean and
median frame time, p99, 1 % low, frames of 33 and of 50 ms or more), and the same-seed pairs go either way. Neither
side had a 10-s window with a wait of 300 ms or more for a virtual core. What this PR still changes is the waits for
a core: the longest wait in a window fell from 177 to 45 ms (medians), the waits of 50 ms or more, every thread's, from
287 to 19, and the time all threads spent waiting for a core by 13 to 17 % in each same-seed pair. The long waits left
on main are low-priority loader threads (tera::FileResourceMgr, PreActorModelCompose,
aglTextureDataMgr::Compaction: 275 of the 287 in main's seed-55 run), never the main thread, which is why the frames
don't move.

Hardware: Windows 11 Home 10.0.26300, RTX 4090 24 GB (NVIDIA 621.24), Core i9-13900K (32 logical processors), 64 GB
RAM.
Scene: Castle Town's market as a child, its south part, moving; output 2560x1440 in a window (shown, not in front),
HDR10, NVIDIA DLAA (2560x1440 to 2560x1440), DLSS Frame Generation 2x, V-Sync Auto (FIFO), capped at 60 by
HOS_FPS_MAX=60. One options file for every run; it is not Auto's pick (Auto on this PC would choose DLSS Quality).
The numbers count the game's own frames, not the made ones.
Method: a scripted route through the control bridge (the same seed on both sides) walking the south market for 300 s
after arriving there, 29 windows of about 10 s. Per run: the windows with a virtual-core wait of 300 ms or more and the
longest wait of each window (the vcores: lines), the waits of 50 ms or more for a core, every thread's, in the
windows (HOS_PROFILE=1 records each one with its thread and the thread that gave the core), the time all threads
spent waiting for a core, the frames of 50 ms or more (a count) and of 33 ms or more (a minute), the 1 % low (1000 over
the mean of the slowest 1 % of frame times), p99, the mean and median frame time. The same switches on both sides:
HOS_PROFILE=1 with its sampler held off, RX_VK_PASS_TIMING=0, HOS_FPS_MAX=60, HOS_WINDOW_NOACTIVATE=1. Both
builds are packs over one base (v3.0.0, 544229a2), each from its commit, with DLSS. Main 868f6be8 does not build on
Windows (#475's near, fixed by #1729), so both sides carry #1729's commit 44ab7f74, which touches neither
host/hos_mem.c nor anything this PR changes: main as 15e051cb, this PR (18bf5321) as 227ceaa5; each run's log reports
its version (v3.0.0-rc.8-46-g15e051cb, v3.0.0-rc.8-51-g227ceaa5). The runs went through the PC's job queue in timing
mode. A warm-up run of each side first (seed 57, not counted: a build prepares its shaders on its first run), then
seeds 55, 56 and 58 in the order main, this PR, this PR, main, main, this PR. Main's first seed-56 run had another
agent's runtime build beside it for about 70 s (the job queue let a job that prepares shaders on every core run beside
it: 18 to 28 cores busy outside the game in 7 of its windows); it is not counted, and main's seed 56 ran again after
the other five. Outside load: 2.0 to 3.1 cores busy outside the game (each run's mean over its windows; same-seed
pairs, this PR minus main: +0.38, +0.62, −0.11). Process Lasso runs on this PC; its configuration has no rule naming
the game.
How to reproduce: a save in Castle Town's market as a child and the settings above; walk the south part (z below ~31)
for 5 minutes, then read the vcores: lines' longest waits and the frame times.

Each run by seed (55, 56, 58), then the median:

Before: main @ 868f6be8 (+44ab7f74) After: this PR @ 18bf5321 (+44ab7f74) Δ
Windows with a core wait of 300 ms or more (of 29) 0, 0, 0: 0 0, 0, 0: 0 none
Longest core wait in a window, median / max (ms) 173/259, 183/274, 177/264: 177/264 45/124¹, 45/120, 39/74: 45/120 −132 / −144
Waits of 50 ms or more for a core, every thread 287, 326, 245: 287 19, 24, 5: 19 −268
Time waiting for a core, all threads (thread-s a second) 1.81, 1.89, 1.59: 1.81 1.57, 1.57, 1.36: 1.57 −13 %
Frames of 50 ms or more (in about 296 s) 11, 3, 8: 8 6, 7, 1: 6 within the spread
Frames of 33 ms or more a minute 63.4, 54.7, 45.8: 54.7 59.7, 59.1, 45.0: 59.1 within the spread
1 % low (fps) 23.45, 24.33, 24.73: 24.33 23.47, 23.78, 24.55: 23.78 within the spread
p99 frame time (ms) 37.45, 36.45, 35.45: 36.45 36.90, 37.09, 35.34: 36.90 within the spread
Average fps (cap 60) 53.9, 54.4, 55.3: 54.4 53.9, 53.9, 55.7: 53.9 within the spread
Mean frame time (ms) 18.57, 18.39, 18.09: 18.39 18.55, 18.54, 17.96: 18.54 within the spread
Median frame time (ms) 16.84, 16.83, 16.78: 16.83 16.88, 16.87, 16.74: 16.87 within the spread

¹ In the first window. On both sides the load just before the market (3.3 s before that window) has waits of 114 to
129 ms; this PR's line in the first window reaches back over them, main's two lines there (9 and 10 ms) were written at
a moment that doesn't. Without the first window, 81 ms.

Same-seed pairs, this PR minus main (seeds 55, 56, 58): mean frame time −0.03, +0.14, −0.13 ms; 1 % low +0.02, −0.55,
−0.17 fps; frames of 22 ms or more −0.9, +0.5, −0.2 points; time waiting for a core −13, −17, −14 %.

Who waited 50 ms or more in main's seed-55 run: tera::FileResourceMgr 124 times, PreActorModelCompose 98,
aglTextureDataMgr::Compaction 53, Porter 7, BaseProcCreateAndDeleteThread 5; the cores were given by the core-1
workers (NavMeshCAStepDepWorker1, BaseProcExecutor1, ModuleSystemWorker1) and the loaders themselves. In this
PR's seed-55 run the same loaders, 19 times.

The first series, on main c507b98c (before the rebase). The same scene, settings and method on main c507b98c,
before #1576, #1339, #1632 and #1663 merged (2026-11-18; its six files in docs/tested/ are
2026-11-18-vcore-region-free-jiro113-s20*.md). There the change was a gain in the hitches:

Before: main @ c507b98c After: this PR @ 2664bb7c Δ
Windows with a core wait of 300 ms or more (of 29) 24, 25, 26: 25 0, 0, 0: 0 −25
Waits of 50 ms or more for a core, every thread 850, 847, 839: 847 42, 39, 20: 39 −808
Frames of 33 ms or more a minute 17.0, 13.0, 13.0: 13.0 1.2, 3.0, 2.0: 2.0 −11.0
1 % low (fps) 27.03, 30.09, 29.30: 29.30 36.56, 34.14, 34.99: 34.99 +5.69
p99 frame time (ms) 30.26, 29.83, 29.55: 29.83 25.45, 26.48, 25.81: 25.81 −4.02
Mean frame time (ms) 18.18, 18.34, 18.34: 18.34 17.73, 17.82, 17.80: 17.80 −0.54

Main's frames are worse in the second series than in the first (frames of 33 ms or more 13 → 55 a minute, 1 % low 29
→ 24 fps; this PR's side too, 2 → 59 a minute). The two series are different sessions, not interleaved, so that
comparison is not claimed; a series on this PC earlier the same day, on main at v3.0.0-rc.8, gave main the same
numbers as the second series. The likely cause is #1632's new default, HOS_NATIVE_ZSTD=2, in which the game's stream
decode keeps its virtual core: c507b98c's default was 1 (the core given up while it decodes), and every run of the
second series logs HOS_NATIVE_ZSTD=2. A separate series on this PC (rc.8, the same market, profiling switches of its
own, so not comparable with the tables above) gave 54.8 fps at the default (one valid run) against 58.3 with
HOS_NATIVE_ZSTD=1 (#1477 (comment)). This PR doesn't
touch the decode. The first series ran at c507b98c's default (mode 1); whether this PR's frame gain comes back with
HOS_NATIVE_ZSTD=1 on current main is not measured.

Flags and settings

None.

Testing

Tested: The rebased tree in the game: this PR's four runs of the second series (18bf5321 with #1729's commit, as
227ceaa5; Windows 11 Home 10.0.26300, RTX 4090, NVIDIA 621.24), a warm-up and three measured runs, each the game's
start, the load to the market and 300 s walking in it: DLSS started; no error and no hang (no the game read no controller for line); no wait for a core of 300 ms or more in the market. The longest wait of each run, of both sides
(0.49 to 0.81 s), comes during the start and the loads before the market, from a loader thread. Before the rebase, on
main c507b98c: a 23-minute run in the game driven by the control bridge, with no profiling switch: the market (2
minutes), then Hyrule Field, Kokiri Forest, Kakariko Village and the Graveyard, back and forth with 35 area changes,
then the market again (4 minutes), with no error and no hang. tests/test_vcore_region_free.py fails on main (7 of its
checks, as above) and passes here (Windows llvm-mingw, Linux gcc and clang).

After the rebase onto main 868f6be8, on this PC:

  • tests/test_host_free_marks.py (#1339's) failed on the rebased tree before its fixture stood in for the core
    (What changed); it passes now, on Windows and Linux, and passes on main as before.
  • python -I -B tests/run_all.py on Windows, main 868f6be8 and this PR's head (ad3c871e) each from a clean
    git archive: main 735 passed, 52 failed, 64 skipped; here 736 passed, 52 failed, 64 skipped. The same 52 fail on
    both, none only here; here one more passes (test_vcore_region_free). One is test_vbytes, which runs past its
    600-s limit on this PC on both; the other 51:
    byte_compile_tracked, test_auto_handheld, test_bug_report, test_bug_report_defaults,
    test_build_long_paths, test_capture_read_once, test_capture_readback_visibility, test_crash_dialog,
    test_crt_options, test_damage_debug_menu, test_dev_packs, test_discover, test_display_startup_failure,
    test_dlss_feature_size, test_draw_stream_visibility, test_failed_compile_keeps_objects,
    test_fsr_image_retirement, test_fsr_uniform_ownership, test_game_menu_mouse_buttons, test_guest_imported,
    test_host_guest_writes, test_hud_layout_row, test_job_queue, test_libc_hooks, test_lift_lookups,
    test_linux_preflight, test_linux_pressure, test_missing_nup, test_pads_after_menu,
    test_parallel_init_order, test_pending_guest_import, test_pipeline_play_cache, test_prepare_cache_save,
    test_present_source_crop, test_present_thread, test_profiling_mode, test_psychov35_fsr3_fg,
    test_readback_timeout_source, test_recorder_sync, test_replay_write_order, test_sdiv_overflow,
    test_slow_frames, test_song_note_cue, test_staging_burst, test_tested_configurations,
    test_texel_buffer_ownership, test_upscaler_rows, test_vcore_escape, test_vk_occlusion_queries,
    test_walk, test_walk_key. (test_tested_configurations fails on main the same way on this PC;
    this PR's six new files in docs/tested/ pass its checks.)
  • The same on Linux (Ubuntu 22.04 under WSL, from a git archive of each, this PR at 72a7a581, before the comment-only
    18bf5321): here 690 passed, 48 failed, 114 skipped;
    main 688 passed, 49 failed, 114 skipped. The 48 fail on main too; main's one more is test_perf_report, which
    passes here. The three that read host/ files and fail (test_host_guest_writes, test_libc_hooks,
    test_vcore_escape) fail on main with the same message on both systems.
  • On Linux at ad3c871e, test_vcore_region_free (g++ and clang++) and test_host_free_marks (gcc and clang) pass.
  • The whole game built from the rebased tree (72a7a581) on Linux (Ubuntu 22.04 under WSL, nx2/make_game.py with the emsdk
    clang and the Linux sysroot, shaders not prepared: no GPU there): longshot and longshot_vk.so built, 0 files
    failed, no warning from the build.
  • On Windows the whole game built from this PR's commit with #1729's commit (44ab7f74) on top, with DLSS: main 868f6be8
    alone doesn't build on Windows (#475 names a counter near in gpu/vk/descriptor_array_census.h, which the Windows
    headers define as nothing; #1729 fixes it). That build ran the runs above.

Not testable by hand: the two cases the region's mark is for, an allocation and a second free of the same address
while its pages are handed back, can't be made to happen from the game on purpose; the game-free test runs both.

Not tested: the rebased tree in the game on Linux; Intel GPUs, the Steam Deck and CPUs with fewer cores (#1632's
freezes were on a Core Ultra 7 155H laptop): the change is the same code on every platform and the hand-back itself is
unchanged; while it runs, the freeing thread now runs beside the game's six virtual cores instead of on one of them
(not measured on a small CPU).

Must be tested:

  • linux, any GPU: build this PR and walk Castle Town's market for a few minutes, expecting it to build, no error, and
    the vcores: lines' longest waits no longer than main's in the market (Test Farm: linux, the market walked for 5
    minutes, the vcores: longest waits against main)
  • steamdeck (a CPU with fewer cores): walk Castle Town's market for a few minutes, then go out to Hyrule Field and back,
    expecting no load to hang (no the game read no controller for over 20 s in longshot_log.txt) and the vcores:
    lines' longest waits in the market no longer than main's (Test Farm: steamdeck, the market walked and an area change,
    against main)

Risks

What could break: another game thread now runs on the core while a region is handed back. The region stays listed,
marked as being freed, until then, so an allocation meanwhile is not given its pages (#1610). A second free of the same
address meanwhile (the guest freeing it twice) finds the mark and does nothing, as on main, where it found no region;
the test checks it.

The freeing thread now waits to take a core back after the hand-back. #1632 found such waits froze loads for 20 s to 5
minutes on an Arc 155H laptop, for a decode that gave its core up around every call; this gives it up once for each
region freed. On main since #1339 that is no new take-back: the renderer's import check before the hand-back gives the
core up and takes one back, once for each region freed; with this PR the check runs without the core (its own give-up
does nothing for a thread that holds none), and the thread takes a core back once, after the hand-back (or the
zeroing) instead of before it. Measured: in the second series (on main 868f6be8, with #1339 and #1632) the Resource Memory thread never waited 50 ms or more for a core in any run, warm-ups included, on either side, over the whole run
(the start, the loads and the market; the profile records every such wait with its thread). In the first series (on
main c507b98c) it waited once, 124 ms, in a load before the market in one of this PR's runs, and never on main; in the
23-minute run with its 35 area changes, never. No run of either series had a load hang. A CPU with fewer cores and an
iGPU laptop are not run (Must be tested).

Turning it off: revert the commit.

Compatibility: Nothing changes.

Issues

  • See #1610: the region kept listed, marked as being freed, until its pages are handed back; a
    second free meanwhile does nothing (its items 1 to 3; item 4 is #432's).
  • See #1150 (merged): the core kept for an invalidate with nothing to wait for; this is the other side.
  • See #327: mask 0 and the guest's core cache, another path.
  • See #249 (closed): named threads take a core first.
  • See #1553 (merged): the core given up around recording diagnostics and large decodes, for the same kind of waits.
  • See #1543 (merged): Tracy zones; a market frame's main thread in one job-loop wait.
  • See #1503: the virtual-core gate's lock and its one-second starve limit.
  • See #1020: performance leads; in the market the main thread waits on its job workers.
  • See #1576 (merged): the game's own work a frame in the same market.
  • See #1339 (merged): the renderer's import check and the zeroing of imported pages before the hand-back, on Windows
    too; the check gives the core up and takes one back for each region freed.
  • See #1542: one of its commits makes taking and giving up a core cheaper (part of #1503); it doesn't touch
    host/hos_mem.c, and the two merge in either order.
  • See #1632 (merged): loads froze on an Arc iGPU while a decode that gave its core up at every call waited to take one
    back; the decode now keeps its core. Risks has this PR's waits for the same kind of take-back.
  • See #1729: main 868f6be8's Windows build (#475's near); both sides of the second series carry its commit.
  • See #1436: its log (Windows, rc.7, i5-12400) has waits of 0.3 to 1 s for a core, 23 of its 31 such vcores: lines
    in the market; not measured on that CPU.
  • See #996: its log (Linux, rc.4) also has waits of 0.5 to 1 s for a core in the market, 9 of its 196 vcores:
    lines; the steady drop it reports while running circles is not claimed here.
  • See #597: rough frame times in the market; no log yet.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what
    can't be run by hand is in Testing's Not testable by hand, with why.
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and
    in Risks.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main. (On 868f6be8, measured there.)
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named).
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported.
  • A file in docs/tested/ for each new measured run (format in docs/tested-configurations.md): six for each
    series, 2026-11-18-vcore-region-free-jiro113-s20*.md and 2026-11-19-vcore-region-free-jiro113-rv*.md, each
    set in its own commit.
  • A game-free test added for the fix, failing on main and passing here.
  • A check under tests/ that reads changed source updated in this PR, not weakened. (test_host_free_marks:
    its fixture stands in for the core given up, and checks it is taken back.)
  • Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. (Linux: the whole game, under WSL.
    Windows: the whole game, with #1729's commit on top: Testing.)

🤖 Generated with Claude Code

**Type:** perf · **Risk:** low · **Tested on:** Windows 11, RTX 4090 · **Needs:** Linux, any GPU ## TL;DR When the game frees a large block of memory, the runtime hands its pages back to the system, for milliseconds, and the freeing thread kept its virtual core throughout, holding up the game's threads waiting for it. Now it gives the core up for that work. Against current main, in 3 runs a side in Castle Town's market, frames are the same (within the spread); waits for a core of 50 ms or more fell from 287 to 19 (medians). On an older main (c507b98c) the change took away waits of 300 ms or more and raised the 1 % low from 29 to 35 fps; main no longer has those waits. ## Breakdown - **Who it helps:** on current main, nothing a player sees in the market's frame rate (Measurements); the game's loader threads wait less for a core there. On main c507b98c, anyone walking around the market (hitches). - **What was wrong:** the game's resource memory thread kept its virtual core while the runtime handed a freed region's pages back to the system, so the game's threads on that core were held up for the whole of it. - **What changes:** the freeing thread gives its virtual core up while the pages are handed back, and takes one again after; the region stays reserved until its pages are handed back. - **What does not change:** what is freed and when, the hand-back itself (`HOS_KEEP_FREED_PAGES` as before), saves, options and caches. - **How it was checked:** 3 runs a side in the south market against main 868f6be8, interleaved after a warm-up of each (medians): frames within the spread (mean frame time 18.39 against 18.54 ms, 1 % low 24.3 against 23.8 fps, the same-seed pairs going either way); windows with a wait for a core of 300 ms or more, none on either side; waits of 50 ms or more for a core, every thread's, 287 on main, 19 here. A game-free test fails on main for the bug's reason and passes here. The rebased tree ran in the game: the four runs of this PR in the series (a warm-up and three measured, 300 s each in the market), no error or hang. - **What is still open:** Linux builds the whole game from the rebased tree (Ubuntu 22.04 under WSL) and ran in the game before the rebase (GrimVisage's comment, an RX 9070 XT); Intel GPUs and the Steam Deck are not run. - **Risk:** low: one more host task gives the core up, as a file read does, once for each region freed; the region's bookkeeping keeps it from being handed out again during the hand-back. The freeing thread then waits to take a core back, the kind of wait #1632 found freezing loads on an Arc iGPU for a decode that gave its core up at every call; on main since #1339 that is no new wait, as the renderer's import check before the hand-back already takes one back for each region freed. In every run of both series, on both sides, that thread never waited 50 ms or more for a core, but once (124 ms, in a load before the market, in the first series) (Risks). ## Why In Castle Town's market, walking in its south part, the `vcores:` log line shows game threads waiting for a virtual core; on main c507b98c (the first series here) they waited 0.3 to 0.9 s, and the frame rate dipped in hitches. Most of those long waits were for core 1. The game's resource memory thread (`Resource Memory`, pinned to core 1) frees memory regions as it streams resources there; each free hands the region's pages back to the system (`DiscardVirtualMemory` on Windows, `MADV_REMOVE` on Linux), milliseconds for a large region, and the thread kept core 1 throughout. The game's core-1 job workers (`ModuleSystemWorker1`, `BaseProcExecutor1`, `NavMeshCAStepDepWorker1`), of a higher priority than the freeing thread, could not have the core until it was done, and the main thread waited for them to finish their jobs. A profiled run on main c507b98c put most of the resource memory thread's extra work in slow frames into that hand-back, with core 1 held. See #1150 (merged): it keeps the core for an invalidate that has nothing to wait for, where giving it up cost more than it saved; this is the other side, a host task long enough that keeping the core holds up the game. See #327 (open: mask 0 and the guest's core cache) and #249 (closed: named threads first) for the other work on the virtual cores: neither touches this path. See #1553 (merged): it gives the core up around the recording diagnostics and large decodes, for waits of the same kind in the market; both series here are on a main that has it. See #1543 (merged): its Tracy zones found a market frame's main thread spending about 10 of 18.6 ms in one job-loop wait. See #1503: the virtual-core gate lets a low-priority thread wait up to a second for a core (`HOS_VCORE_STARVE_US`); this PR does not change the gate, it takes away the host work that kept core 1 busy. See #1542 (open): one of its commits makes taking and giving up a core cheaper (part of #1503); it doesn't touch `host/hos_mem.c` and keeps `hos_vcore_away`/`hos_vcore_back`, so the two merge in either order. See #1632 (merged; on main in the second series): on an Arc iGPU, loads froze while the native zstd decode, which gave its core up around every call, waited to take one back; the decode now keeps its core. This PR gives the core up once for each region freed, for milliseconds of work; Risks has the waits measured. See #1020: its leads find the market's frame waiting on the main thread, which waits on its job workers. See #1610: `hos_region_free` took the region off the list before handing its pages back, so an allocation meanwhile could be given pages about to be wiped. Once the hand-back no longer holds the core, the window is wider, so this PR does what #1610 proposes in its items 1 to 3: the region stays listed, marked as being freed, until its pages are handed back, and a second free of it meanwhile does nothing (item 4 is #432's). See #1339 (merged; on main in the second series): before the hand-back, the runtime now asks the renderer, on Windows too (Linux already did), whether it imported the pages, and zeroes imported pages in place instead of handing them back. Asking gives the core up and takes one back, once for each region freed. With this PR the thread gives its core up before the question and takes one back once, after the hand-back or the zeroing: the question's own give-up does nothing for a thread that holds no core. On main the hand-back itself still runs with the core held. Main no longer has the market's waits of 300 ms or more (Measurements); which of the changes merged since c507b98c took them away is not established. Players' logs with the same waits: #1436 (Windows, rc.7, an i5-12400 with 6 cores) has 31 `vcores:` lines with a wait of 300 ms or more for a core, 23 of them after it reaches the market, many at the one-second limit; #996 (Linux, rc.4) has waits of 0.5 to 1 s in the market in 9 of its 196 `vcores:` lines. Both are older than #1339 and #1576; whether current main still has those waits on those PCs, and whether this PR changes them there, is not measured. #597 (rough frame times in the market on a Ryzen 7 9800X3D) has no log yet. See #1576 (merged; on main in the second series): it makes the game's own work a frame cheaper in the same market. The two touch different files. ## What changed `hos_region_free` (`nn::os::FreeAddressRegion`) used to take the region off its list, then hand its pages back with the thread's virtual core held. Now it gives the core up for the hand-back, as a file read does, and takes the region off the list only once the hand-back is done, so a region allocated meanwhile cannot be given pages that are being handed back. - host: `hos_region_free` in `host/hos_mem.c`: under the lock, finds the region, marks it as being freed and marks its pages; lets the lock go, `hos_vcore_away()`, `discard_pages()`; then removes the region under the lock and `hos_vcore_back()` if the thread had a core. An address that is no region, or a region already being freed, returns at once, keeping the core. A region being freed stays in the list, so `hos_region_alloc` skips it and the control bridge's range checks (`hos_mem_region`, `hos_regions`) still read it as mapped; `hos_region_alloc` writes its new entry unmarked. The comments in `hos_region_free` and `hos_mem_region` say why only its own `hos_vcore_back` takes a core back, and that a region being freed still reads as mapped. - tests: `tests/test_vcore_region_free.py` compiles the actual `hos_region_free` and `hos_region_alloc` with stand-ins and checks that the hand-back runs once, without the core and outside the lock, with the region still listed; that the region then leaves the list with the others kept in order and the core taken back once; that an unknown address keeps the core and a thread holding no core takes none; that a second free of the region during its hand-back does nothing and leaves it listed; that a region of no size leaves the list; and that a region allocated while another is being freed can itself be freed. On main 7 of its checks fail: "the discard runs without the virtual core", "the region stays listed through its discard (no allocation is handed its pages)", "the core is held again after it, taken once, and the lock let go", "an allocation while the region is discarded is not handed its pages (#1610)", "after the discard the region allocated meanwhile stays listed and the freed one is gone", "a second free of the region while it is discarded leaves it listed (its address is not handed out again yet)" and "after both frees the core is held again, taken once, and the lock let go". - tests: `tests/test_host_free_marks.py` (from #1339) compiles `host/hos_mem.c` with stand-ins of its own, which since the rebase have to include `hos_vcore_away` and `hos_vcore_back`; its fixture now stands in for them, counting the cores given up, and checks after each region free that every core given up was taken back. Its other checks are unchanged. ## Measurements **Verdict:** no change in frames against current main. On main 868f6be8 every frame row is within the spread (mean and median frame time, p99, 1 % low, frames of 33 and of 50 ms or more), and the same-seed pairs go either way. Neither side had a 10-s window with a wait of 300 ms or more for a virtual core. What this PR still changes is the waits for a core: the longest wait in a window fell from 177 to 45 ms (medians), the waits of 50 ms or more, every thread's, from 287 to 19, and the time all threads spent waiting for a core by 13 to 17 % in each same-seed pair. The long waits left on main are low-priority loader threads (`tera::FileResourceMgr`, `PreActorModelCompose`, `aglTextureDataMgr::Compaction`: 275 of the 287 in main's seed-55 run), never the main thread, which is why the frames don't move. Hardware: Windows 11 Home 10.0.26300, RTX 4090 24 GB (NVIDIA 621.24), Core i9-13900K (32 logical processors), 64 GB RAM. Scene: Castle Town's market as a child, its south part, moving; output 2560x1440 in a window (shown, not in front), HDR10, NVIDIA DLAA (2560x1440 to 2560x1440), DLSS Frame Generation 2x, V-Sync Auto (FIFO), capped at 60 by `HOS_FPS_MAX=60`. One options file for every run; it is not Auto's pick (Auto on this PC would choose DLSS Quality). The numbers count the game's own frames, not the made ones. Method: a scripted route through the control bridge (the same seed on both sides) walking the south market for 300 s after arriving there, 29 windows of about 10 s. Per run: the windows with a virtual-core wait of 300 ms or more and the longest wait of each window (the `vcores:` lines), the waits of 50 ms or more for a core, every thread's, in the windows (`HOS_PROFILE=1` records each one with its thread and the thread that gave the core), the time all threads spent waiting for a core, the frames of 50 ms or more (a count) and of 33 ms or more (a minute), the 1 % low (1000 over the mean of the slowest 1 % of frame times), p99, the mean and median frame time. The same switches on both sides: `HOS_PROFILE=1` with its sampler held off, `RX_VK_PASS_TIMING=0`, `HOS_FPS_MAX=60`, `HOS_WINDOW_NOACTIVATE=1`. Both builds are packs over one base (v3.0.0, 544229a2), each from its commit, with DLSS. Main 868f6be8 does not build on Windows (#475's `near`, fixed by #1729), so both sides carry #1729's commit 44ab7f74, which touches neither `host/hos_mem.c` nor anything this PR changes: main as 15e051cb, this PR (18bf5321) as 227ceaa5; each run's log reports its version (v3.0.0-rc.8-46-g15e051cb, v3.0.0-rc.8-51-g227ceaa5). The runs went through the PC's job queue in timing mode. A warm-up run of each side first (seed 57, not counted: a build prepares its shaders on its first run), then seeds 55, 56 and 58 in the order main, this PR, this PR, main, main, this PR. Main's first seed-56 run had another agent's runtime build beside it for about 70 s (the job queue let a job that prepares shaders on every core run beside it: 18 to 28 cores busy outside the game in 7 of its windows); it is not counted, and main's seed 56 ran again after the other five. Outside load: 2.0 to 3.1 cores busy outside the game (each run's mean over its windows; same-seed pairs, this PR minus main: +0.38, +0.62, −0.11). Process Lasso runs on this PC; its configuration has no rule naming the game. How to reproduce: a save in Castle Town's market as a child and the settings above; walk the south part (z below ~31) for 5 minutes, then read the `vcores:` lines' longest waits and the frame times. Each run by seed (55, 56, 58), then the median: | | Before: main @ 868f6be8 (+44ab7f74) | After: this PR @ 18bf5321 (+44ab7f74) | Δ | |---|---|---|---| | Windows with a core wait of 300 ms or more (of 29) | 0, 0, 0: **0** | 0, 0, 0: **0** | none | | Longest core wait in a window, median / max (ms) | 173/259, 183/274, 177/264: **177/264** | 45/124¹, 45/120, 39/74: **45/120** | −132 / −144 | | Waits of 50 ms or more for a core, every thread | 287, 326, 245: **287** | 19, 24, 5: **19** | −268 | | Time waiting for a core, all threads (thread-s a second) | 1.81, 1.89, 1.59: **1.81** | 1.57, 1.57, 1.36: **1.57** | −13 % | | Frames of 50 ms or more (in about 296 s) | 11, 3, 8: **8** | 6, 7, 1: **6** | within the spread | | Frames of 33 ms or more a minute | 63.4, 54.7, 45.8: **54.7** | 59.7, 59.1, 45.0: **59.1** | within the spread | | 1 % low (fps) | 23.45, 24.33, 24.73: **24.33** | 23.47, 23.78, 24.55: **23.78** | within the spread | | p99 frame time (ms) | 37.45, 36.45, 35.45: **36.45** | 36.90, 37.09, 35.34: **36.90** | within the spread | | Average fps (cap 60) | 53.9, 54.4, 55.3: **54.4** | 53.9, 53.9, 55.7: **53.9** | within the spread | | Mean frame time (ms) | 18.57, 18.39, 18.09: **18.39** | 18.55, 18.54, 17.96: **18.54** | within the spread | | Median frame time (ms) | 16.84, 16.83, 16.78: **16.83** | 16.88, 16.87, 16.74: **16.87** | within the spread | ¹ In the first window. On both sides the load just before the market (3.3 s before that window) has waits of 114 to 129 ms; this PR's line in the first window reaches back over them, main's two lines there (9 and 10 ms) were written at a moment that doesn't. Without the first window, 81 ms. Same-seed pairs, this PR minus main (seeds 55, 56, 58): mean frame time −0.03, +0.14, −0.13 ms; 1 % low +0.02, −0.55, −0.17 fps; frames of 22 ms or more −0.9, +0.5, −0.2 points; time waiting for a core −13, −17, −14 %. Who waited 50 ms or more in main's seed-55 run: `tera::FileResourceMgr` 124 times, `PreActorModelCompose` 98, `aglTextureDataMgr::Compaction` 53, `Porter` 7, `BaseProcCreateAndDeleteThread` 5; the cores were given by the core-1 workers (`NavMeshCAStepDepWorker1`, `BaseProcExecutor1`, `ModuleSystemWorker1`) and the loaders themselves. In this PR's seed-55 run the same loaders, 19 times. **The first series, on main c507b98c (before the rebase).** The same scene, settings and method on main c507b98c, before #1576, #1339, #1632 and #1663 merged (2026-11-18; its six files in `docs/tested/` are `2026-11-18-vcore-region-free-jiro113-s20*.md`). There the change was a gain in the hitches: | | Before: main @ c507b98c | After: this PR @ 2664bb7c | Δ | |---|---|---|---| | Windows with a core wait of 300 ms or more (of 29) | 24, 25, 26: **25** | 0, 0, 0: **0** | −25 | | Waits of 50 ms or more for a core, every thread | 850, 847, 839: **847** | 42, 39, 20: **39** | −808 | | Frames of 33 ms or more a minute | 17.0, 13.0, 13.0: **13.0** | 1.2, 3.0, 2.0: **2.0** | −11.0 | | 1 % low (fps) | 27.03, 30.09, 29.30: **29.30** | 36.56, 34.14, 34.99: **34.99** | +5.69 | | p99 frame time (ms) | 30.26, 29.83, 29.55: **29.83** | 25.45, 26.48, 25.81: **25.81** | −4.02 | | Mean frame time (ms) | 18.18, 18.34, 18.34: **18.34** | 17.73, 17.82, 17.80: **17.80** | −0.54 | Main's frames are worse in the second series than in the first (frames of 33 ms or more 13 → 55 a minute, 1 % low 29 → 24 fps; this PR's side too, 2 → 59 a minute). The two series are different sessions, not interleaved, so that comparison is not claimed; a series on this PC earlier the same day, on main at v3.0.0-rc.8, gave main the same numbers as the second series. The likely cause is #1632's new default, `HOS_NATIVE_ZSTD=2`, in which the game's stream decode keeps its virtual core: c507b98c's default was 1 (the core given up while it decodes), and every run of the second series logs `HOS_NATIVE_ZSTD=2`. A separate series on this PC (rc.8, the same market, profiling switches of its own, so not comparable with the tables above) gave 54.8 fps at the default (one valid run) against 58.3 with `HOS_NATIVE_ZSTD=1` (https://git.magicbean.dev/MagicBeanDev/Longshot/issues/1477#issuecomment-53913). This PR doesn't touch the decode. The first series ran at c507b98c's default (mode 1); whether this PR's frame gain comes back with `HOS_NATIVE_ZSTD=1` on current main is not measured. ### Flags and settings None. ## Testing **Tested:** The rebased tree in the game: this PR's four runs of the second series (18bf5321 with #1729's commit, as 227ceaa5; Windows 11 Home 10.0.26300, RTX 4090, NVIDIA 621.24), a warm-up and three measured runs, each the game's start, the load to the market and 300 s walking in it: DLSS started; no error and no hang (no `the game read no controller for` line); no wait for a core of 300 ms or more in the market. The longest wait of each run, of both sides (0.49 to 0.81 s), comes during the start and the loads before the market, from a loader thread. Before the rebase, on main c507b98c: a 23-minute run in the game driven by the control bridge, with no profiling switch: the market (2 minutes), then Hyrule Field, Kokiri Forest, Kakariko Village and the Graveyard, back and forth with 35 area changes, then the market again (4 minutes), with no error and no hang. `tests/test_vcore_region_free.py` fails on main (7 of its checks, as above) and passes here (Windows llvm-mingw, Linux gcc and clang). After the rebase onto main 868f6be8, on this PC: - `tests/test_host_free_marks.py` (#1339's) failed on the rebased tree before its fixture stood in for the core (What changed); it passes now, on Windows and Linux, and passes on main as before. - `python -I -B tests/run_all.py` on Windows, main 868f6be8 and this PR's head (ad3c871e) each from a clean `git archive`: main 735 passed, 52 failed, 64 skipped; here 736 passed, 52 failed, 64 skipped. The same 52 fail on both, none only here; here one more passes (`test_vcore_region_free`). One is `test_vbytes`, which runs past its 600-s limit on this PC on both; the other 51: `byte_compile_tracked`, `test_auto_handheld`, `test_bug_report`, `test_bug_report_defaults`, `test_build_long_paths`, `test_capture_read_once`, `test_capture_readback_visibility`, `test_crash_dialog`, `test_crt_options`, `test_damage_debug_menu`, `test_dev_packs`, `test_discover`, `test_display_startup_failure`, `test_dlss_feature_size`, `test_draw_stream_visibility`, `test_failed_compile_keeps_objects`, `test_fsr_image_retirement`, `test_fsr_uniform_ownership`, `test_game_menu_mouse_buttons`, `test_guest_imported`, `test_host_guest_writes`, `test_hud_layout_row`, `test_job_queue`, `test_libc_hooks`, `test_lift_lookups`, `test_linux_preflight`, `test_linux_pressure`, `test_missing_nup`, `test_pads_after_menu`, `test_parallel_init_order`, `test_pending_guest_import`, `test_pipeline_play_cache`, `test_prepare_cache_save`, `test_present_source_crop`, `test_present_thread`, `test_profiling_mode`, `test_psychov35_fsr3_fg`, `test_readback_timeout_source`, `test_recorder_sync`, `test_replay_write_order`, `test_sdiv_overflow`, `test_slow_frames`, `test_song_note_cue`, `test_staging_burst`, `test_tested_configurations`, `test_texel_buffer_ownership`, `test_upscaler_rows`, `test_vcore_escape`, `test_vk_occlusion_queries`, `test_walk`, `test_walk_key`. (`test_tested_configurations` fails on main the same way on this PC; this PR's six new files in `docs/tested/` pass its checks.) - The same on Linux (Ubuntu 22.04 under WSL, from a `git archive` of each, this PR at 72a7a581, before the comment-only 18bf5321): here 690 passed, 48 failed, 114 skipped; main 688 passed, 49 failed, 114 skipped. The 48 fail on main too; main's one more is `test_perf_report`, which passes here. The three that read `host/` files and fail (`test_host_guest_writes`, `test_libc_hooks`, `test_vcore_escape`) fail on main with the same message on both systems. - On Linux at ad3c871e, `test_vcore_region_free` (g++ and clang++) and `test_host_free_marks` (gcc and clang) pass. - The whole game built from the rebased tree (72a7a581) on Linux (Ubuntu 22.04 under WSL, `nx2/make_game.py` with the emsdk clang and the Linux sysroot, shaders not prepared: no GPU there): `longshot` and `longshot_vk.so` built, 0 files failed, no warning from the build. - On Windows the whole game built from this PR's commit with #1729's commit (44ab7f74) on top, with DLSS: main 868f6be8 alone doesn't build on Windows (#475 names a counter `near` in `gpu/vk/descriptor_array_census.h`, which the Windows headers define as nothing; #1729 fixes it). That build ran the runs above. **Not testable by hand:** the two cases the region's mark is for, an allocation and a second free of the same address while its pages are handed back, can't be made to happen from the game on purpose; the game-free test runs both. **Not tested:** the rebased tree in the game on Linux; Intel GPUs, the Steam Deck and CPUs with fewer cores (#1632's freezes were on a Core Ultra 7 155H laptop): the change is the same code on every platform and the hand-back itself is unchanged; while it runs, the freeing thread now runs beside the game's six virtual cores instead of on one of them (not measured on a small CPU). **Must be tested:** - linux, any GPU: build this PR and walk Castle Town's market for a few minutes, expecting it to build, no error, and the `vcores:` lines' longest waits no longer than main's in the market (Test Farm: linux, the market walked for 5 minutes, the `vcores:` longest waits against main) - steamdeck (a CPU with fewer cores): walk Castle Town's market for a few minutes, then go out to Hyrule Field and back, expecting no load to hang (no `the game read no controller for` over 20 s in longshot_log.txt) and the `vcores:` lines' longest waits in the market no longer than main's (Test Farm: steamdeck, the market walked and an area change, against main) ## Risks **What could break:** another game thread now runs on the core while a region is handed back. The region stays listed, marked as being freed, until then, so an allocation meanwhile is not given its pages (#1610). A second free of the same address meanwhile (the guest freeing it twice) finds the mark and does nothing, as on main, where it found no region; the test checks it. The freeing thread now waits to take a core back after the hand-back. #1632 found such waits froze loads for 20 s to 5 minutes on an Arc 155H laptop, for a decode that gave its core up around every call; this gives it up once for each region freed. On main since #1339 that is no new take-back: the renderer's import check before the hand-back gives the core up and takes one back, once for each region freed; with this PR the check runs without the core (its own give-up does nothing for a thread that holds none), and the thread takes a core back once, after the hand-back (or the zeroing) instead of before it. Measured: in the second series (on main 868f6be8, with #1339 and #1632) the `Resource Memory` thread never waited 50 ms or more for a core in any run, warm-ups included, on either side, over the whole run (the start, the loads and the market; the profile records every such wait with its thread). In the first series (on main c507b98c) it waited once, 124 ms, in a load before the market in one of this PR's runs, and never on main; in the 23-minute run with its 35 area changes, never. No run of either series had a load hang. A CPU with fewer cores and an iGPU laptop are not run (Must be tested). **Turning it off:** revert the commit. **Compatibility:** Nothing changes. ## Issues - See #1610: the region kept listed, marked as being freed, until its pages are handed back; a second free meanwhile does nothing (its items 1 to 3; item 4 is #432's). - See #1150 (merged): the core kept for an invalidate with nothing to wait for; this is the other side. - See #327: mask 0 and the guest's core cache, another path. - See #249 (closed): named threads take a core first. - See #1553 (merged): the core given up around recording diagnostics and large decodes, for the same kind of waits. - See #1543 (merged): Tracy zones; a market frame's main thread in one job-loop wait. - See #1503: the virtual-core gate's lock and its one-second starve limit. - See #1020: performance leads; in the market the main thread waits on its job workers. - See #1576 (merged): the game's own work a frame in the same market. - See #1339 (merged): the renderer's import check and the zeroing of imported pages before the hand-back, on Windows too; the check gives the core up and takes one back for each region freed. - See #1542: one of its commits makes taking and giving up a core cheaper (part of #1503); it doesn't touch `host/hos_mem.c`, and the two merge in either order. - See #1632 (merged): loads froze on an Arc iGPU while a decode that gave its core up at every call waited to take one back; the decode now keeps its core. Risks has this PR's waits for the same kind of take-back. - See #1729: main 868f6be8's Windows build (#475's `near`); both sides of the second series carry its commit. - See #1436: its log (Windows, rc.7, i5-12400) has waits of 0.3 to 1 s for a core, 23 of its 31 such `vcores:` lines in the market; not measured on that CPU. - See #996: its log (Linux, rc.4) also has waits of 0.5 to 1 s for a core in the market, 9 of its 196 `vcores:` lines; the steady drop it reports while running circles is not claimed here. - See #597: rough frame times in the market; no log yet. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand, with why. - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. (On 868f6be8, measured there.) - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported. - [x] A file in `docs/tested/` for each new measured run (format in `docs/tested-configurations.md`): six for each series, `2026-11-18-vcore-region-free-jiro113-s20*.md` and `2026-11-19-vcore-region-free-jiro113-rv*.md`, each set in its own commit. - [x] A game-free test added for the fix, failing on `main` and passing here. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. (`test_host_free_marks`: its fixture stands in for the core given up, and checks it is taken back.) - [x] Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. (Linux: the whole game, under WSL. Windows: the whole game, with #1729's commit on top: Testing.) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Fails on main: hos_region_free holds the thread's virtual core through discard_pages, and takes the region off the list
before the discard, so an allocation meanwhile could be handed pages that are being discarded: the check makes one, with
the freed region the highest hole of its size, and asks that it be placed elsewhere (#1610). With the region kept listed
through its discard, the check also asks that a second free of it meanwhile (the guest freeing it twice) do nothing
(#1610), that a region of no size still leaves the list, and that a region allocated meanwhile can be freed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The discard (DiscardVirtualMemory on Windows, MADV_REMOVE on Linux) hands a region's pages back to the system and takes
milliseconds for a large one. The game frees on its resource memory thread, which shares a core with workers of a higher
priority; with the core held through the discard they waited for all of it. The thread now gives the core up for the
discard, as for a file read. The region stays listed, marked as being freed, until its pages are discarded, so that no
AllocateAddressRegion meanwhile is handed pages being discarded, and leaves the list before the thread waits for its
core again. A second free of the address meanwhile (the guest freeing it twice) finds the mark and does nothing, as it
found no region before (#1610).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
docs(tested): six runs in Castle Town's market, FreeAddressRegion's discard without the core against main
Some checks reported errors
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Failing after 8s
beanstalk/approval approved by HumanBean, llun (double-reviewed)
beanstalk/any 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
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
ba18666043
Series 20 on an RTX 4090 and i9-13900K, Windows 11: main c507b98c (seeds 55, 56, 58) and this PR's 2664bb7c (the same
seeds), 300 s each in the south market, interleaved after a warm-up of each side, through the job queue in timing mode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: Windows 11 Home 10.0.26300, RTX 4090 (NVIDIA 621.24), i9-13900K: this PR's build (2664bb7c) in the game: a 23-minute scripted run through Castle Town's market, Hyrule Field, Kokiri Forest, Kakariko and the Graveyard and back (35 area changes), no error or hang; after the start no wait for a core reached 300 ms; and 3 measured 300-s runs in the south market against main c507b98c (Measurements).

Tested in game: Windows 11 Home 10.0.26300, RTX 4090 (NVIDIA 621.24), i9-13900K: this PR's build (2664bb7c) in the game: a 23-minute scripted run through Castle Town's market, Hyrule Field, Kokiri Forest, Kakariko and the Graveyard and back (35 area changes), no error or hang; after the start no wait for a core reached 300 ms; and 3 measured 300-s runs in the south market against main c507b98c (Measurements).
Jiro113 changed title from WIP: perf(host): FreeAddressRegion gives its virtual core up while the region's pages are discarded to perf(host): FreeAddressRegion gives its virtual core up while the region's pages are discarded 2026-11-18 20:13:42 +00:00
Member

@Beanstalk

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

Commit ba18666 · tier reviewed · approved by llun · dashboard

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

The plan compares main and the pull request in Castle Town Market and across repeated loads through Hyrule Field and Kakariko Village. It measures frame-time tails, hitches, load times and memory, with pictures to catch visible corruption. Crashes, stalled loads, significant performance or memory regressions, and substantial picture differences fail the plan. The two paired runs take about 22 minutes per tester; the market measurement is stationary after movement, so it does not reproduce the reported walking benchmark exactly.

  • Where: any (any PC, 1-2 reports).
  • market-and-loads: from the repository's save kokiri-start, then teleport to Market, move the stick, measure market for 60 s (after 5 s warm-up), take the picture market to compare with main, 2 times: teleport to Hyrule Field, teleport to Kakariko Village, teleport to Market, measure return-market for 20 s (after 5 s warm-up), take the picture return-market to compare with main; 2 runs on each side.
  • Measured: crashes, frame times, stutters and hitches, load times, memory and CPU time.
  • The PR fails if: it crashes; or a picture differs from main by more than 5%; or peak memory is more than 15% above main; or longest load is more than 25% above main; or frame time (p99) is more than 20% above main; or frame time (worst 1%) is more than 20% above main.
  • Time: about 26 min of game runs per tester (4 game starts), plus the two builds.

Done (started 20:17 UTC, last report 21:48 UTC). Comment @Beanstalk to run it again.

Target Reports Crash Frame p99 (ms) vs main VRAM peak (MB) vs main Result
any · 1: windows+nvidia+nvidia-proprietary+dgpu NVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.24.0; 2: windows+nvidia+nvidia-proprietary+dgpu NVIDIA GeForce RTX 3090, 621.24.0 2/1 1 2 none — — error

Measurements · any

Verdict: could not be judged on any (2/1 report).

Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu NVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.24.0 AMD Ryzen 7 5800H with Radeon Graphics, 16 GB RAM; 2: windows+nvidia+nvidia-proprietary+dgpu NVIDIA GeForce RTX 3090, 621.24.0 AMD Ryzen 9 5900X 12-Core Processor, 128 GB RAM
Scene: market-and-loads, from the repository's save kokiri-start; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-loads: 2 game starts a side, market 60 s after 5 s warm-up, return-market 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (@Beanstalk on this PR runs it again)

Nothing was measured: no metric came back.

Flags and settings

None: the plan varied no setting, switch or build option.

Markdown for the PR description
## Measurements

**Verdict:** could not be judged on any (2/1 report).

Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.24.0` `AMD Ryzen 7 5800H with Radeon Graphics, 16 GB RAM`; 2: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3090, 621.24.0` `AMD Ryzen 9 5900X 12-Core Processor, 128 GB RAM`  
Scene: market-and-loads, from the repository's save kokiri-start; each cell's settings and switches as the table names them  
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-loads: 2 game starts a side, market 60 s after 5 s warm-up, return-market 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports  
How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again)

Nothing was measured: no metric came back.

### Flags and settings

None: the plan varied no setting, switch or build option.
<!-- beanstalk:previous --> <details><summary>Beanstalk test farm · an earlier run: commit <code>ba18666</code> (the newer results are in a comment below)</summary> Commit `ba18666` · tier **reviewed** · approved by llun · [dashboard](https://beanstalk.magicbean.dev/prs/1646) **What will be tested** · AI plan (`gpt-6.1-terra`) The plan compares main and the pull request in Castle Town Market and across repeated loads through Hyrule Field and Kakariko Village. It measures frame-time tails, hitches, load times and memory, with pictures to catch visible corruption. Crashes, stalled loads, significant performance or memory regressions, and substantial picture differences fail the plan. The two paired runs take about 22 minutes per tester; the market measurement is stationary after movement, so it does not reproduce the reported walking benchmark exactly. - **Where:** any (any PC, 1-2 reports). - **market-and-loads:** from the repository's save `kokiri-start`, then teleport to Market, move the stick, measure market for 60 s (after 5 s warm-up), take the picture market to compare with main, 2 times: teleport to Hyrule Field, teleport to Kakariko Village, teleport to Market, measure return-market for 20 s (after 5 s warm-up), take the picture return-market to compare with main; 2 runs on each side. - **Measured:** crashes, frame times, stutters and hitches, load times, memory and CPU time. - **The PR fails if:** it crashes; or a picture differs from main by more than 5%; or peak memory is more than 15% above main; or longest load is more than 25% above main; or frame time (p99) is more than 20% above main; or frame time (worst 1%) is more than 20% above main. - **Time:** about 26 min of game runs per tester (4 game starts), plus the two builds. Done (started 20:17 UTC, last report 21:48 UTC). Comment `@Beanstalk` to run it again. | Target | Reports | Crash | Frame p99 (ms) vs main | VRAM peak (MB) vs main | Result | | --- | --- | --- | --- | --- | --- | | any · 1: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.24.0`; 2: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3090, 621.24.0` | 2/1 [1](https://beanstalk.magicbean.dev/reports/rp_615f9a49da08b76e) [2](https://beanstalk.magicbean.dev/reports/rp_86ea319829c97ca3) | none | — | — | error | #### Measurements · any **Verdict:** could not be judged on any (2/1 report). Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.24.0` `AMD Ryzen 7 5800H with Radeon Graphics, 16 GB RAM`; 2: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3090, 621.24.0` `AMD Ryzen 9 5900X 12-Core Processor, 128 GB RAM` Scene: market-and-loads, from the repository's save kokiri-start; each cell's settings and switches as the table names them Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-loads: 2 game starts a side, market 60 s after 5 s warm-up, return-market 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again) Nothing was measured: no metric came back. ### Flags and settings None: the plan varied no setting, switch or build option. <details><summary>Markdown for the PR description</summary> ```markdown ## Measurements **Verdict:** could not be judged on any (2/1 report). Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.24.0` `AMD Ryzen 7 5800H with Radeon Graphics, 16 GB RAM`; 2: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3090, 621.24.0` `AMD Ryzen 9 5900X 12-Core Processor, 128 GB RAM` Scene: market-and-loads, from the repository's save kokiri-start; each cell's settings and switches as the table names them Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-loads: 2 game starts a side, market 60 s after 5 s warm-up, return-market 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again) Nothing was measured: no metric came back. ### Flags and settings None: the plan varied no setting, switch or build option. ``` </details> </details>
HumanBean left a comment

The code looks right to me. What holds this back is the evidence: it is on a main 49 commits old, and two of those commits change this exact path.

Blocking

  1. Measured and run on a main that has since changed this path. Every run and the 23-minute game run are on c507b98c. Since then main has merged #1339, which rewrites discard_pages (on Windows too, it now asks the renderer whether the pages are imported, and that question gives the core up and takes it back, then zeroes imported pages), and #1663, which changes how the game's YieldThread gives up its virtual core. Both change the waits this PR measures. The description says itself that the PR "is rebased and measured again before it leaves WIP", and "Rebased on current main" is unchecked, but the PR is out of WIP without either. The merged tree has never run in the game. The fix: rebase onto main@origin (it merges cleanly), run it in the game once, repeat the 3+3 market series against current main, update Measurements and docs/tested/, and say whether the gain holds now that main itself gives the core up once per free.
  2. The PR description check fails (PR description / Description follows the template, run 38042). Please look at what it reports. The two unchecked boxes and the "before this leaves WIP" wording are likely causes. Fix it with the rebase.

Thread safety (read, no change needed)

  • Locks: hos_region_free releases the hos_mem.c lock before hos_vcore_away() and takes it again only to unlist the region. No lock is held across the discard or across hos_vcore_back(). Its only caller is the HLE for FreeAddressRegion, which holds no other lock.
  • What can run during the discard: another thread on the freed core, and any other thread's hos_region_alloc, hos_region_free, hos_mem_region or hos_regions. The region stays listed with freeing set, so first-fit allocation steps over it. A second free sees the mark and returns, as main does when it finds nothing. The unlisting looks the entry up by address and mark, so a memmove from an allocation in between cannot make it remove the wrong one. A new entry clears the mark it inherits from the slot it takes. All of this is covered by the test.
  • Nested give-up on current main: rx_guest_imported's own hos_vcore_away() sees vc_held == 0 and returns vc_escaped, which the outer away has already cleared. So only the outer hos_vcore_back() takes a core back, once per free, the same count as on main since #1339. The question's hos_guest_fill now runs without a core, which host/hos.h allows ("Any thread may call them at any time").
  • Windows vs Linux: both discards (DiscardVirtualMemory/MEM_RESET, and MADV_REMOVE on the memfd) already ran outside the lock on main. Only the core is new. The large-pages return and the web build's stub hos_vcore_away are unaffected. There is no Linux build or run of this branch yet.

Measurements: present, done properly for the main they ran on (Windows 11, RTX 4090, 3 interleaved runs a side after warm-ups, same seeds, per-run values given). The gain is well outside the spread: 1% low 27.0-30.1 against 34.1-36.6 fps, p99 29.6-30.3 against 25.5-26.5 ms, windows with a core wait of 300 ms or more 24-26 against 0 of 29. The median frame time change is within the spread, as the description says. But these numbers are for c507b98c, not for what would merge (point 1). The Test Farm's "failed" label is the farm, not the change: both reports (RTX 3050 Ti laptop, RTX 3090) show no crash and "Nothing was measured: no metric came back" on either side, so there was nothing to judge. Run it again after the rebase.

Still needed for hardware: Linux (AMD RX 6000-9000 and NVIDIA) and the Steam Deck. The Deck matters here because the freeing thread now takes its core back against busier cores on a small CPU (the kind of wait #1632 found on an Arc laptop). The PR's own Must be tested asks for both, which is right. Ask @Beanstalk for them after the rebase, walking the market (the earlier plan stood still after moving).

host/hos_mem.c:79 (outside the diff): Nit, not blocking: while a region is being discarded, the control bridge still reports it as mapped, so a bridge read there can return zeros or a mix of old and new bytes. That is intended (the description says so) and harmless, but a word in hos_mem_region's comment would save the next reader the question.

The code looks right to me. What holds this back is the evidence: it is on a main 49 commits old, and two of those commits change this exact path. **Blocking** 1. **Measured and run on a main that has since changed this path.** Every run and the 23-minute game run are on c507b98c. Since then main has merged https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1339, which rewrites `discard_pages` (on Windows too, it now asks the renderer whether the pages are imported, and that question gives the core up and takes it back, then zeroes imported pages), and https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1663, which changes how the game's `YieldThread` gives up its virtual core. Both change the waits this PR measures. The description says itself that the PR "is rebased and measured again before it leaves WIP", and "Rebased on current `main`" is unchecked, but the PR is out of WIP without either. The merged tree has never run in the game. The fix: rebase onto `main@origin` (it merges cleanly), run it in the game once, repeat the 3+3 market series against current main, update Measurements and `docs/tested/`, and say whether the gain holds now that main itself gives the core up once per free. 2. **The PR description check fails** (`PR description / Description follows the template`, run 38042). Please look at what it reports. The two unchecked boxes and the "before this leaves WIP" wording are likely causes. Fix it with the rebase. **Thread safety (read, no change needed)** - Locks: `hos_region_free` releases the `hos_mem.c` lock before `hos_vcore_away()` and takes it again only to unlist the region. No lock is held across the discard or across `hos_vcore_back()`. Its only caller is the HLE for `FreeAddressRegion`, which holds no other lock. - What can run during the discard: another thread on the freed core, and any other thread's `hos_region_alloc`, `hos_region_free`, `hos_mem_region` or `hos_regions`. The region stays listed with `freeing` set, so first-fit allocation steps over it. A second free sees the mark and returns, as main does when it finds nothing. The unlisting looks the entry up by address and mark, so a `memmove` from an allocation in between cannot make it remove the wrong one. A new entry clears the mark it inherits from the slot it takes. All of this is covered by the test. - Nested give-up on current main: `rx_guest_imported`'s own `hos_vcore_away()` sees `vc_held == 0` and returns `vc_escaped`, which the outer away has already cleared. So only the outer `hos_vcore_back()` takes a core back, once per free, the same count as on main since https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1339. The question's `hos_guest_fill` now runs without a core, which `host/hos.h` allows ("Any thread may call them at any time"). - Windows vs Linux: both discards (`DiscardVirtualMemory`/`MEM_RESET`, and `MADV_REMOVE` on the memfd) already ran outside the lock on main. Only the core is new. The large-pages return and the web build's stub `hos_vcore_away` are unaffected. There is no Linux build or run of this branch yet. **Measurements:** present, done properly for the main they ran on (Windows 11, RTX 4090, 3 interleaved runs a side after warm-ups, same seeds, per-run values given). The gain is well outside the spread: 1% low 27.0-30.1 against 34.1-36.6 fps, p99 29.6-30.3 against 25.5-26.5 ms, windows with a core wait of 300 ms or more 24-26 against 0 of 29. The median frame time change is within the spread, as the description says. But these numbers are for c507b98c, not for what would merge (point 1). The Test Farm's "failed" label is the farm, not the change: both reports (RTX 3050 Ti laptop, RTX 3090) show no crash and "Nothing was measured: no metric came back" on either side, so there was nothing to judge. Run it again after the rebase. **Still needed for hardware:** Linux (AMD RX 6000-9000 and NVIDIA) and the Steam Deck. The Deck matters here because the freeing thread now takes its core back against busier cores on a small CPU (the kind of wait https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1632 found on an Arc laptop). The PR's own Must be tested asks for both, which is right. Ask `@Beanstalk` for them after the rebase, walking the market (the earlier plan stood still after moving). **`host/hos_mem.c:79`** (outside the diff): Nit, not blocking: while a region is being discarded, the control bridge still reports it as mapped, so a bridge read there can return zeros or a mix of old and new bytes. That is intended (the description says so) and harmless, but a word in `hos_mem_region`'s comment would save the next reader the question.
host/hos_mem.c Outdated
@ -198,0 +212,4 @@
}
UNLOCK();
if (!found) return;
const int away = hos_vcore_away();
Owner

On current main, discard_pages calls rx_guest_imported, whose own hos_vcore_away() now returns 0 here (no core held, vc_escaped cleared by this away), so only this function's hos_vcore_back() takes a core back. That is correct, and it would be worth one clause in the comment above after the rebase, since the description leans on it.

On current main, `discard_pages` calls `rx_guest_imported`, whose own `hos_vcore_away()` now returns 0 here (no core held, `vc_escaped` cleared by this away), so only this function's `hos_vcore_back()` takes a core back. That is correct, and it would be worth one clause in the comment above after the rebase, since the description leans on it.
Owner

@Beanstalk

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

Commit ba18666 · tier double-reviewed · approved by HumanBean, llun · dashboard

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

The plan compares main and the pull request in Castle Town Market and across repeated loads through Hyrule Field and Kakariko Village. It measures frame-time tails, hitches, load times and memory, with pictures to catch visible corruption. Crashes, stalled loads, significant performance or memory regressions, and substantial picture differences fail the plan. The two paired runs take about 22 minutes per tester; the market measurement is stationary after movement, so it does not reproduce the reported walking benchmark exactly.

  • Where: any (any PC, 1-2 reports).
  • market-and-loads: from the repository's save kokiri-start, then teleport to Market, move the stick, measure market for 60 s (after 5 s warm-up), take the picture market to compare with main, 2 times: teleport to Hyrule Field, teleport to Kakariko Village, teleport to Market, measure return-market for 20 s (after 5 s warm-up), take the picture return-market to compare with main; 2 runs on each side.
  • Measured: crashes, frame times, stutters and hitches, load times, memory and CPU time.
  • The PR fails if: it crashes; or a picture differs from main by more than 5%; or peak memory is more than 15% above main; or longest load is more than 25% above main; or frame time (p99) is more than 20% above main; or frame time (worst 1%) is more than 20% above main.
  • Time: about 26 min of game runs per tester (4 game starts), plus the two builds.

Done (started 07:46 UTC, last report 08:59 UTC). Run 2: started again by HumanBean. Comment @Beanstalk to run it again.

Target Reports Crash Frame p99 (ms) vs main VRAM peak (MB) vs main Result
any · 1: windows+nvidia+nvidia-proprietary+dgpu NVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.24.0; 2: windows+amd+amd-proprietary+dgpu AMD Radeon RX 9070 XT, 2.0.416 2/1 1 2 none — — error

Measurements · any

Verdict: could not be judged on any (2/1 report).

Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu NVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.24.0 AMD Ryzen 7 5800H with Radeon Graphics, 16 GB RAM; 2: windows+amd+amd-proprietary+dgpu AMD Radeon RX 9070 XT, 2.0.416 AMD Ryzen 9 5900X 12-Core Processor, 32 GB RAM
Scene: market-and-loads, from the repository's save kokiri-start; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-loads: 2 game starts a side, market 60 s after 5 s warm-up, return-market 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (@Beanstalk on this PR runs it again)

Nothing was measured: no metric came back.

Flags and settings

None: the plan varied no setting, switch or build option.

Markdown for the PR description
## Measurements

**Verdict:** could not be judged on any (2/1 report).

Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.24.0` `AMD Ryzen 7 5800H with Radeon Graphics, 16 GB RAM`; 2: windows+amd+amd-proprietary+dgpu `AMD Radeon RX 9070 XT, 2.0.416` `AMD Ryzen 9 5900X 12-Core Processor, 32 GB RAM`  
Scene: market-and-loads, from the repository's save kokiri-start; each cell's settings and switches as the table names them  
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-loads: 2 game starts a side, market 60 s after 5 s warm-up, return-market 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports  
How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again)

Nothing was measured: no metric came back.

### Flags and settings

None: the plan varied no setting, switch or build option.
<!-- beanstalk:previous --> <details><summary>Beanstalk test farm · an earlier run: commit <code>ba18666</code>, run 2 (the newer results are in a comment below)</summary> Commit `ba18666` · tier **double-reviewed** · approved by HumanBean, llun · [dashboard](https://beanstalk.magicbean.dev/prs/1646) **What will be tested** · AI plan (`gpt-6.1-terra`) The plan compares main and the pull request in Castle Town Market and across repeated loads through Hyrule Field and Kakariko Village. It measures frame-time tails, hitches, load times and memory, with pictures to catch visible corruption. Crashes, stalled loads, significant performance or memory regressions, and substantial picture differences fail the plan. The two paired runs take about 22 minutes per tester; the market measurement is stationary after movement, so it does not reproduce the reported walking benchmark exactly. - **Where:** any (any PC, 1-2 reports). - **market-and-loads:** from the repository's save `kokiri-start`, then teleport to Market, move the stick, measure market for 60 s (after 5 s warm-up), take the picture market to compare with main, 2 times: teleport to Hyrule Field, teleport to Kakariko Village, teleport to Market, measure return-market for 20 s (after 5 s warm-up), take the picture return-market to compare with main; 2 runs on each side. - **Measured:** crashes, frame times, stutters and hitches, load times, memory and CPU time. - **The PR fails if:** it crashes; or a picture differs from main by more than 5%; or peak memory is more than 15% above main; or longest load is more than 25% above main; or frame time (p99) is more than 20% above main; or frame time (worst 1%) is more than 20% above main. - **Time:** about 26 min of game runs per tester (4 game starts), plus the two builds. Done (started 07:46 UTC, last report 08:59 UTC). Run 2: started again by HumanBean. Comment `@Beanstalk` to run it again. | Target | Reports | Crash | Frame p99 (ms) vs main | VRAM peak (MB) vs main | Result | | --- | --- | --- | --- | --- | --- | | any · 1: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.24.0`; 2: windows+amd+amd-proprietary+dgpu `AMD Radeon RX 9070 XT, 2.0.416` | 2/1 [1](https://beanstalk.magicbean.dev/reports/rp_ebd37268b68d3867) [2](https://beanstalk.magicbean.dev/reports/rp_c21083af0517724e) | none | — | — | error | #### Measurements · any **Verdict:** could not be judged on any (2/1 report). Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.24.0` `AMD Ryzen 7 5800H with Radeon Graphics, 16 GB RAM`; 2: windows+amd+amd-proprietary+dgpu `AMD Radeon RX 9070 XT, 2.0.416` `AMD Ryzen 9 5900X 12-Core Processor, 32 GB RAM` Scene: market-and-loads, from the repository's save kokiri-start; each cell's settings and switches as the table names them Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-loads: 2 game starts a side, market 60 s after 5 s warm-up, return-market 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again) Nothing was measured: no metric came back. ### Flags and settings None: the plan varied no setting, switch or build option. <details><summary>Markdown for the PR description</summary> ```markdown ## Measurements **Verdict:** could not be judged on any (2/1 report). Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.24.0` `AMD Ryzen 7 5800H with Radeon Graphics, 16 GB RAM`; 2: windows+amd+amd-proprietary+dgpu `AMD Radeon RX 9070 XT, 2.0.416` `AMD Ryzen 9 5900X 12-Core Processor, 32 GB RAM` Scene: market-and-loads, from the repository's save kokiri-start; each cell's settings and switches as the table names them Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-loads: 2 game starts a side, market 60 s after 5 s warm-up, return-market 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again) Nothing was measured: no metric came back. ### Flags and settings None: the plan varied no setting, switch or build option. ``` </details> </details>
Contributor

Tested in game on Linux: Fedora 45 (kernel 7.3.4), AMD Radeon RX 9070 XT (RADV GFX1201, Mesa 26.2.7), Ryzen 5 5600X (12 logical processors), 32 GB RAM. This PR's head ba186660 against its base c507b98c, two test builds made the same way from one game dump (a host-only change, so both sides prepare the same shaders). No errors, hangs or device losses in any run.

Castle Town market (the main check): the confirmation on Linux. Long waits for a virtual core fall by about 80% and none of 100 ms or more remain in the first run; frame times are within the spread.

120 s market laps, 12:00 base 1 base 2 PR 1 PR 2
Waits for a core of 50 ms or more 35 32 7 17
Waits of 100 ms or more 15 15 0 4
Longest wait 355 ms 319 ms 88 ms 648 ms
Average fps 41.9 41.3 41.6 42.9
p99 frame time 36.7 ms 37.9 ms 36.0 ms 35.5 ms
Frames of 100 ms or more 4 7 1 6

PR 2's four long waits are another kind: all are sead::MainThread holding its own core (615 and 648 ms, the others the threads queued behind it), not the free path this PR changes.

Hyrule Field (supporting): within the spread on every number, waits included. The field has far fewer core waits to begin with (median 4 of 100 ms or more on base, 1 here), and its worst drops are the main thread's own work.

120 s, out of the Castle Town gate base 1 base 2 base 3 PR 1 PR 2 PR 3
Waits of 100 ms or more 4 10 2 0 1 4
Waits of 300 ms or more 0 2 0 0 0 0
Average fps 48.6 49.7 49.2 50.6 49.4 48.5
p99 frame time 32.9 ms 33.3 ms 32.3 ms 31.3 ms 33.9 ms 30.7 ms

Settings: the player's own (Custom preset), 2560x1440 fullscreen, HDR10, AMD FSR 4 (1920x1080 to 2560x1440), V-Sync Auto (mailbox), no frame cap, frame generation off, FPS counter off; one kept options file for every run. Threaded rendering Auto (on). HOS_PROFILE=1 on both sides (frames from its presents trace, the waits from its virtual-core wait records).
Method: a scripted route through the control bridge from the repository save kokiri-start. Market: the debug teleport to the Market, the clock at 12:00, then laps between the gate and the fountain, position-steered, 120 s. Field: the same teleport, out of the gate into Hyrule Field, then laps along Link's facing between 20 m and 320 m out, 120 s. A warm-up run of each side first, then interleaved (base, PR, base, PR); Link's hearts protected (HOS_OOT_PROTECT_HEARTS=1) so an enemy can't end a run.

Tested in game on Linux: Fedora 45 (kernel 7.3.4), AMD Radeon RX 9070 XT (RADV GFX1201, Mesa 26.2.7), Ryzen 5 5600X (12 logical processors), 32 GB RAM. This PR's head `ba186660` against its base `c507b98c`, two test builds made the same way from one game dump (a host-only change, so both sides prepare the same shaders). No errors, hangs or device losses in any run. **Castle Town market (the main check):** the confirmation on Linux. Long waits for a virtual core fall by about 80% and none of 100 ms or more remain in the first run; frame times are within the spread. | 120 s market laps, 12:00 | base 1 | base 2 | PR 1 | PR 2 | |---|---|---|---|---| | Waits for a core of 50 ms or more | 35 | 32 | 7 | 17 | | Waits of 100 ms or more | 15 | 15 | 0 | 4 | | Longest wait | 355 ms | 319 ms | 88 ms | 648 ms | | Average fps | 41.9 | 41.3 | 41.6 | 42.9 | | p99 frame time | 36.7 ms | 37.9 ms | 36.0 ms | 35.5 ms | | Frames of 100 ms or more | 4 | 7 | 1 | 6 | PR 2's four long waits are another kind: all are `sead::MainThread` holding its own core (615 and 648 ms, the others the threads queued behind it), not the free path this PR changes. **Hyrule Field (supporting):** within the spread on every number, waits included. The field has far fewer core waits to begin with (median 4 of 100 ms or more on base, 1 here), and its worst drops are the main thread's own work. | 120 s, out of the Castle Town gate | base 1 | base 2 | base 3 | PR 1 | PR 2 | PR 3 | |---|---|---|---|---|---|---| | Waits of 100 ms or more | 4 | 10 | 2 | 0 | 1 | 4 | | Waits of 300 ms or more | 0 | 2 | 0 | 0 | 0 | 0 | | Average fps | 48.6 | 49.7 | 49.2 | 50.6 | 49.4 | 48.5 | | p99 frame time | 32.9 ms | 33.3 ms | 32.3 ms | 31.3 ms | 33.9 ms | 30.7 ms | Settings: the player's own (Custom preset), 2560x1440 fullscreen, HDR10, AMD FSR 4 (1920x1080 to 2560x1440), V-Sync Auto (mailbox), no frame cap, frame generation off, FPS counter off; one kept options file for every run. Threaded rendering Auto (on). `HOS_PROFILE=1` on both sides (frames from its presents trace, the waits from its virtual-core wait records). Method: a scripted route through the control bridge from the repository save `kokiri-start`. Market: the debug teleport to the Market, the clock at 12:00, then laps between the gate and the fountain, position-steered, 120 s. Field: the same teleport, out of the gate into Hyrule Field, then laps along Link's facing between 20 m and 320 m out, 120 s. A warm-up run of each side first, then interleaved (base, PR, base, PR); Link's hearts protected (`HOS_OOT_PROTECT_HEARTS=1`) so an enemy can't end a run.
Jiro113 force-pushed perf/vcore-improvements from ba18666043
Some checks reported errors
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Failing after 8s
beanstalk/approval approved by HumanBean, llun (double-reviewed)
beanstalk/any 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
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 72a7a581df
Some checks failed
beanstalk/approval not approved yet
PR description / Description follows the template (pull_request_target) Successful in 4s
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
2026-11-19 09:10:16 +00:00
Compare
Member

Beanstalk test farm

Commit ad3c871 · 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 `ad3c871` · approved by nobody yet · [dashboard](https://beanstalk.magicbean.dev/prs/1646) A member of `BigBeans` can review this commit and comment `@Beanstalk` to test it.
Review of #1646: on current main discard_pages asks the renderer (rx_guest_imported), whose own give-up answers 0
for a thread that holds no core, so the core is taken back once for each region freed. And the control bridge may
read a region while its pages are handed back: zeros or mixed bytes, harmless.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
docs(tested): six south-market runs of the region free against main 868f6be8 (#1729's fix on both sides)
Some checks are pending
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
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (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) Successful in 3s
beanstalk/approval not approved yet
ad3c871e74
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

@HumanBean thanks for the review. Point by point:

1. Rebased, run in the game, measured again. The branch is on main 868f6be8 (72a7a581, with test_host_free_marks's fixture standing in for the core the discard now gives up). The rebased tree ran in the game: this PR's four runs of the new series (a warm-up and three measured, 300 s each in the market), no error and no hang. The 3+3 south-market series is redone against main 868f6be8 (main 868f6be8 doesn't build on Windows, #475's near, so both sides carry #1729's commit 44ab7f74), with its six files in docs/tested/ (2026-11-19-vcore-region-free-jiro113-rv*.md), and Measurements rewritten.

Does the gain hold? Not in frames. On current main every frame row is within the spread (mean frame time 18.39 against 18.54 ms, 1 % low 24.3 against 23.8 fps, same-seed pairs going either way), and main no longer has the market's waits of 300 ms or more (0 windows on both sides, against 24-26 of 29 on c507b98c). What still changes is the waits for a core: the longest wait in a window 177 → 45 ms, waits of 50 ms or more 287 → 19 (medians), the time all threads spend waiting for a core −13 to −17 % in each same-seed pair. The long waits left on main are low-priority loader threads (tera::FileResourceMgr, PreActorModelCompose, aglTextureDataMgr::Compaction), never the main thread, which is why the frames don't move. The TL;DR, Breakdown and Measurements now say this; the c507b98c table stays as the first series. I kept perf, as the change still cuts the core waits; if you'd rather it not merge for that alone, say so.

Main's frames are worse in this series than on c507b98c, on both sides. The likely cause is #1632's new default HOS_NATIVE_ZSTD=2 (c507b98c's default was 1; every run here logs mode 2), as in #1477 (comment). This PR doesn't touch the decode; whether its frame gain comes back with HOS_NATIVE_ZSTD=1 on current main is not measured.

2. The description check passes locally (scripts/check_pr_description.py): rebased, boxes ticked, no WIP wording left.

Nits: done in 18bf5321: hos_region_free's comment says why only its own hos_vcore_back takes a core back (the nested away in rx_guest_imported finds no core held), and hos_mem_region's says a region being freed still reads as mapped, so a bridge read can see zeros or a mix.

Tests: python -I -B tests/run_all.py on Windows: main 735 passed / 52 failed / 64 skipped, this PR 736 / 52 / 64; the same 52 fail on both (test_vbytes runs past its time limit on this PC on both), and test_vcore_region_free passes here. Linux (WSL): the whole game builds from the rebased tree, and at ad3c871e test_vcore_region_free and test_host_free_marks pass with gcc and clang; run_all as in Testing.

Still needed: Linux and the Steam Deck, as Must be tested says.

@HumanBean thanks for the review. Point by point: **1. Rebased, run in the game, measured again.** The branch is on main 868f6be8 (72a7a581, with `test_host_free_marks`'s fixture standing in for the core the discard now gives up). The rebased tree ran in the game: this PR's four runs of the new series (a warm-up and three measured, 300 s each in the market), no error and no hang. The 3+3 south-market series is redone against main 868f6be8 (main 868f6be8 doesn't build on Windows, #475's `near`, so both sides carry #1729's commit 44ab7f74), with its six files in `docs/tested/` (`2026-11-19-vcore-region-free-jiro113-rv*.md`), and Measurements rewritten. **Does the gain hold? Not in frames.** On current main every frame row is within the spread (mean frame time 18.39 against 18.54 ms, 1 % low 24.3 against 23.8 fps, same-seed pairs going either way), and main no longer has the market's waits of 300 ms or more (0 windows on both sides, against 24-26 of 29 on c507b98c). What still changes is the waits for a core: the longest wait in a window 177 → 45 ms, waits of 50 ms or more 287 → 19 (medians), the time all threads spend waiting for a core −13 to −17 % in each same-seed pair. The long waits left on main are low-priority loader threads (`tera::FileResourceMgr`, `PreActorModelCompose`, `aglTextureDataMgr::Compaction`), never the main thread, which is why the frames don't move. The TL;DR, Breakdown and Measurements now say this; the c507b98c table stays as the first series. I kept `perf`, as the change still cuts the core waits; if you'd rather it not merge for that alone, say so. Main's frames are worse in this series than on c507b98c, on both sides. The likely cause is #1632's new default `HOS_NATIVE_ZSTD=2` (c507b98c's default was 1; every run here logs mode 2), as in https://git.magicbean.dev/MagicBeanDev/Longshot/issues/1477#issuecomment-53913. This PR doesn't touch the decode; whether its frame gain comes back with `HOS_NATIVE_ZSTD=1` on current main is not measured. **2. The description check** passes locally (`scripts/check_pr_description.py`): rebased, boxes ticked, no WIP wording left. **Nits:** done in 18bf5321: `hos_region_free`'s comment says why only its own `hos_vcore_back` takes a core back (the nested away in `rx_guest_imported` finds no core held), and `hos_mem_region`'s says a region being freed still reads as mapped, so a bridge read can see zeros or a mix. **Tests:** `python -I -B tests/run_all.py` on Windows: main 735 passed / 52 failed / 64 skipped, this PR 736 / 52 / 64; the same 52 fail on both (`test_vbytes` runs past its time limit on this PC on both), and `test_vcore_region_free` passes here. Linux (WSL): the whole game builds from the rebased tree, and at ad3c871e `test_vcore_region_free` and `test_host_free_marks` pass with gcc and clang; run_all as in Testing. **Still needed:** Linux and the Steam Deck, as Must be tested says.
Author
Contributor

Two more looks at the market's core-1 waits on Windows, on main 8b0ea786 without this PR: same PC, scene, options file and route as the series in the description (Windows 11, RTX 4090, NVIDIA 621.24, i9-13900K; south market, cap 60, HOS_PROFILE=1, DLSS on). The captures and exports stay on this PC; below are only numbers read from them.

1. Who holds core 1 while the loaders wait (Tracy). A LONGSHOT_TRACY=1 build (its Windows link: #1765) with local zones around discard_pages's callers and branches (an experiment, in no PR), 60 s captured 30 s into the market leg, seed 55, run as a user (TRACY_NO_SAMPLING=1). Two captures, the same picture:

  • The loader threads (tera::FileResourceMgr, PreActorModelCompose, aglTextureDataMgr::Compaction and a few others) waited 50 ms or more for a core 121 times in the minute: 11.9 s summed, 6.8 s with the overlaps merged.
  • While they waited, core 1 was held by Resource Memory 55 % of the time, BaseProcExecutor1 23 %, ModuleSystemWorker1 19 % and NavMeshCAStepDepWorker1 5 % (the other capture: 54, 22, 20, 5).
  • Of Resource Memory's time on the core during those waits, 72 % is the hand-back of freed regions, all of it from FreeAddressRegion (FreeMemoryPages was never called): 58 % DiscardVirtualMemory (14,524 calls, 16.5 GB, median 85 µs, p99 4.7 ms), 11 % zeroing pages the renderer imported (24,331 calls, 14.4 GB), 3 % asking the renderer whether it imported them. About 30 GB are freed a minute.
  • That question took 968 ms in the minute but held the core for 222 ms: the rest is the thread waiting to take a core back after it (#1339's give-up), the wait this PR folds into one per region.

So this PR's give-up covers about three quarters of what Resource Memory does on core 1 while the loaders wait, about 40 % of the core's time in those waits; the rest goes to the game's own core-1 workers and to Resource Memory's other work.

2. No hand-back at all (HOS_KEEP_FREED_PAGES=1). One runtime of main 8b0ea786, the switch unset (A) against set (B), the series' protocol: 300 s each in the south market, a warm-up of each side (seed 57, not counted), then A55, B55, B56, A56, A58, B58, through the job queue in timing mode. A program outside the queue took about 30 cores for about 70 s during A55, B56 and A56 (the queue's noise check reads 0 on Windows), so only the 10-s windows where other programs used 5 cores or fewer are counted:

windows fps 1 % low longest wait for a core (median of windows) game's RAM at the end
A55 15 51.97 25.3 192 ms 13.9 GB
A56 20 51.50 25.1 184 ms 14.0 GB
A58 29 52.53 26.1 170 ms 14.0 GB
B55, HOS_KEEP_FREED_PAGES=1 29 52.40 26.2 78 ms 14.6 GB
B56, HOS_KEEP_FREED_PAGES=1 14 51.89 27.3 66 ms 14.6 GB
B58, HOS_KEEP_FREED_PAGES=1 29 52.52 26.6 78 ms 14.6 GB

Keeping the freed pages takes the long waits away much as this PR does (the longest wait a window from 170–192 to 66–78 ms; this PR on 868f6be8: 177 to 45 ms, a different main and series, so not a direct comparison), and like this PR moves no frame: fps and p99 frame time (33–35 ms) are within the spread; the 1 % low is about 1 fps higher with the switch, from few windows, not established. It costs about 0.6 GB of resident memory, flat over the 5 minutes. Nothing here argues for HOS_KEEP_FREED_PAGES=1 as a default: this PR takes the waits away without keeping the memory. And both agree that in this scene at cap 60 the loaders' waits for core 1 no longer bound the frame.

Two more looks at the market's core-1 waits on Windows, on main 8b0ea786 **without this PR**: same PC, scene, options file and route as the series in the description (Windows 11, RTX 4090, NVIDIA 621.24, i9-13900K; south market, cap 60, `HOS_PROFILE=1`, DLSS on). The captures and exports stay on this PC; below are only numbers read from them. **1. Who holds core 1 while the loaders wait (Tracy).** A `LONGSHOT_TRACY=1` build (its Windows link: #1765) with local zones around `discard_pages`'s callers and branches (an experiment, in no PR), 60 s captured 30 s into the market leg, seed 55, run as a user (`TRACY_NO_SAMPLING=1`). Two captures, the same picture: - The loader threads (`tera::FileResourceMgr`, `PreActorModelCompose`, `aglTextureDataMgr::Compaction` and a few others) waited 50 ms or more for a core 121 times in the minute: 11.9 s summed, 6.8 s with the overlaps merged. - While they waited, core 1 was held by `Resource Memory` 55 % of the time, `BaseProcExecutor1` 23 %, `ModuleSystemWorker1` 19 % and `NavMeshCAStepDepWorker1` 5 % (the other capture: 54, 22, 20, 5). - Of `Resource Memory`'s time on the core during those waits, 72 % is the hand-back of freed regions, all of it from `FreeAddressRegion` (`FreeMemoryPages` was never called): 58 % `DiscardVirtualMemory` (14,524 calls, 16.5 GB, median 85 µs, p99 4.7 ms), 11 % zeroing pages the renderer imported (24,331 calls, 14.4 GB), 3 % asking the renderer whether it imported them. About 30 GB are freed a minute. - That question took 968 ms in the minute but held the core for 222 ms: the rest is the thread waiting to take a core back after it (#1339's give-up), the wait this PR folds into one per region. So this PR's give-up covers about three quarters of what `Resource Memory` does on core 1 while the loaders wait, about 40 % of the core's time in those waits; the rest goes to the game's own core-1 workers and to `Resource Memory`'s other work. **2. No hand-back at all (`HOS_KEEP_FREED_PAGES=1`).** One runtime of main 8b0ea786, the switch unset (A) against set (B), the series' protocol: 300 s each in the south market, a warm-up of each side (seed 57, not counted), then A55, B55, B56, A56, A58, B58, through the job queue in timing mode. A program outside the queue took about 30 cores for about 70 s during A55, B56 and A56 (the queue's noise check reads 0 on Windows), so only the 10-s windows where other programs used 5 cores or fewer are counted: | | windows | fps | 1 % low | longest wait for a core (median of windows) | game's RAM at the end | |---|---|---|---|---|---| | A55 | 15 | 51.97 | 25.3 | 192 ms | 13.9 GB | | A56 | 20 | 51.50 | 25.1 | 184 ms | 14.0 GB | | A58 | 29 | 52.53 | 26.1 | 170 ms | 14.0 GB | | B55, `HOS_KEEP_FREED_PAGES=1` | 29 | 52.40 | 26.2 | 78 ms | 14.6 GB | | B56, `HOS_KEEP_FREED_PAGES=1` | 14 | 51.89 | 27.3 | 66 ms | 14.6 GB | | B58, `HOS_KEEP_FREED_PAGES=1` | 29 | 52.52 | 26.6 | 78 ms | 14.6 GB | Keeping the freed pages takes the long waits away much as this PR does (the longest wait a window from 170–192 to 66–78 ms; this PR on 868f6be8: 177 to 45 ms, a different main and series, so not a direct comparison), and like this PR moves no frame: fps and p99 frame time (33–35 ms) are within the spread; the 1 % low is about 1 fps higher with the switch, from few windows, not established. It costs about 0.6 GB of resident memory, flat over the 5 minutes. Nothing here argues for `HOS_KEEP_FREED_PAGES=1` as a default: this PR takes the waits away without keeping the memory. And both agree that in this scene at cap 60 the loaders' waits for core 1 no longer bound the frame.
Contributor

Tested in the game on Windows 11 with an RTX 4070 (NVIDIA 616.56) and a Ryzen 9 7900X: this head ad3c871e with #1729 merged locally so it compiles on Windows, against main 868f6be8 with #1729. It was an A/B in Hyrule Field while looking into #1720.

The route, the same in every run: a Fire Temple save, teleport to Hyrule Field, Switch age to child, Set time 21:00, then about 2 minutes running around the field fighting the Stalchildren that spawn, with camera turns. Settings: cap 90, DLSS Quality, frame generation off, Reflex and V-Sync on, with RX_VK_PASS_TIMING=1 and HOS_THREAD_TIMES=5. Each run started cold in its own game folder, and a person played. The numbers come from 120-present windows from the field's arrival; a fight window is one with 200 or more dispatches a frame.

main this PR, run 1 this PR, run 2
core waits over 50 ms in the field 17 (worst 236 ms): tera::FileResourceMgr 9, PreActorModelCompose 3, aglTextureDataMgr::Compaction 2, others 3 1 (62 ms, GeneralFormatAsync_) 0
typical longest wait in a 5-s window (median) 14.9 ms 6.5 ms 15.4 ms
fight fps (median, lowest; 8-11 windows) 69.4, 55.3 68.3, 58.9 68.5, 62.0
other play fps (median) 76.9 75.8 76.0
  • It does what it says: the field's long waits for a core (the loading threads, all on core 1) are gone.
  • No frame-rate change in fights: those waits slowed the loading, not the frames, here.
  • No regression seen in the loads: each run, main included, has one wait of about 1,000 ms during the Switch age map reload. It is the same with and without this PR.

No crash, device loss or fatal in any run, and each ended with a clean quit (exit 0). One run per side for main, so the fps rows are within the noise of playing by hand.

Tested in the game on Windows 11 with an RTX 4070 (NVIDIA 616.56) and a Ryzen 9 7900X: this head `ad3c871e` with #1729 merged locally so it compiles on Windows, against main `868f6be8` with #1729. It was an A/B in Hyrule Field while looking into #1720. **The route, the same in every run:** a Fire Temple save, teleport to Hyrule Field, Switch age to child, Set time 21:00, then about 2 minutes running around the field fighting the Stalchildren that spawn, with camera turns. Settings: cap 90, DLSS Quality, frame generation off, Reflex and V-Sync on, with `RX_VK_PASS_TIMING=1` and `HOS_THREAD_TIMES=5`. Each run started cold in its own game folder, and a person played. The numbers come from 120-present windows from the field's arrival; a fight window is one with 200 or more dispatches a frame. | | main | this PR, run 1 | this PR, run 2 | |---|---|---|---| | core waits over 50 ms in the field | **17** (worst 236 ms): `tera::FileResourceMgr` 9, `PreActorModelCompose` 3, `aglTextureDataMgr::Compaction` 2, others 3 | **1** (62 ms, `GeneralFormatAsync_`) | **0** | | typical longest wait in a 5-s window (median) | 14.9 ms | 6.5 ms | 15.4 ms | | fight fps (median, lowest; 8-11 windows) | 69.4, 55.3 | 68.3, 58.9 | 68.5, 62.0 | | other play fps (median) | 76.9 | 75.8 | 76.0 | - **It does what it says:** the field's long waits for a core (the loading threads, all on core 1) are gone. - **No frame-rate change in fights:** those waits slowed the loading, not the frames, here. - **No regression seen in the loads:** each run, main included, has one wait of about 1,000 ms during the Switch age map reload. It is the same with and without this PR. No crash, device loss or fatal in any run, and each ended with a clean quit (exit 0). One run per side for main, so the fps rows are within the noise of playing by hand.
HumanBean deleted branch perf/vcore-improvements 2026-11-20 17:28:35 +00:00
Some checks are pending
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
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (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) Successful in 3s
beanstalk/approval not approved yet
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
6 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!1646
No description provided.