WIP: perf(host): four switches read on per-call paths are read once #1952

Draft
siantm wants to merge 3 commits from siantm/Longshot:perf/switches-read-once into main
Contributor

Summary

Four switches were looked up in the environment every time the code that reads them ran, and the C runtime's getenv
walks the whole environment at each call:

  • HOS_NO_MOVIES at every nn::fs::OpenFile that opens a file for reading (host/nn_fs.c);
  • HOS_RES_SCALE at every present while the Insert menu's Resolution row is set (realtime_step, host/nn_vi.c);
  • HOS_VIDEO_RGBA for every decoded movie picture (queue_frame, host/nn_video.c);
  • RX_VK_LOG_PARTIAL at every partial texture upload (texture_touch, gpu/vk/vk_texture.cpp).

The first three are now read once at the start: hos_fs_env, hos_video_env and hos_vi_env, which game_main calls
next to its HOS_TRACE read, once the environment is set (longshot_env.txt) and before the game's main thread is
made; HOS_RES_SCALE is also parsed there, and realtime_step applies the kept value where it applied the looked-up
one (at each present, the same value, with no first-use flag). The game's threads read
the values without a lock, written before those threads exist. The renderer has no such start, so RX_VK_LOG_PARTIAL
stays a C++ function-local static const (its initialisation is thread-safe), now looked up by the first partial upload
only: a whole upload passes no guard. What each switch does is unchanged. (Main's mirror_budget already reads
RX_VK_MIRROR_MB once; the change this comes from, d7dc45e2 on exp/x86-asm-sync, also did that one.)

Read first: hos_fs_env, hos_video_env, hos_vi_env and their call in game_main (host/hos_main.c);
tests/test_vcore_fs_open.py, which runs OpenFile with HOS_NO_MOVIES flipped after the start's read, and
tests/test_switches_read_at_start.py.

Testing

Tested: Windows 11, i7-9700, RTX 4060 (NVIDIA 610.88), llvm-mingw clang 23.1.5; game-free checks and a
micro-benchmark only. This change has not run in the game on this PC yet (Still to test). Each check ran in a hidden
console of its own, in one job of the PC's job queue (fb-1952-4), on this branch rebased onto main @ 6e1521a7, head
e43ef403:

  • python -I -B tests/test_vcore_fs_open.py: ok, in a fresh process each for HOS_NO_MOVIES unset, 0, off, 1
    and yes, the switch flipped after the start's read: the movies follow the value at the start. It fails at the
    checks' commit 641ace07 (no start read yet), and on three wrong caches written into copies of host/nn_fs.c (0 taken
    for not yet read, read at the first movie, read at the first OpenFile).
  • python -I -B tests/test_switches_read_at_start.py: ok (the three calls in game_main before the game's threads, no
    read left in OpenFile, queue_frame or realtime_step, RX_VK_LOG_PARTIAL inside the partial branch; the
    Resolution block with HOS_RES_SCALE unset, 0.5 and empty, flipped after the start's read, and two live menu
    changes without it). It fails at 641ace07.
  • host/nn_fs.c, host/nn_vi.c, host/nn_video.c, host/hos_main.c and gpu/vk/vk_texture.cpp compiled to objects
    with the build's own commands (llvm-mingw, not linked; the game was not built or run).
  • python -I -B tests/run_all.py --strict --changed origin/main (the checks that read a changed file, 8 at once): 132
    passed, 31 failed, 12 skipped. 14 of the 31 fail on main @ 6e1521a7 too, run by name in the PC's job queue
    (fb-1952-2 and fb-1952-3): test_crash_dialog.py, test_crash_record.py, test_dev_packs.py,
    test_display_startup_failure.py, test_host_guest_writes.py, test_libc_hooks.py, test_lift_cache.py,
    test_linux_pressure.py, test_mods_list.py, test_perf_report.py, test_profiling_mode.py,
    test_readback_timeout_source.py, test_slow_frames.py, test_vcore_escape.py. The other 17 compiled nothing in
    that run nor in the runs on main (no Vulkan headers on the jobs' path: "not found: vulkan_headers (--strict)").
    Rerun with the headers (job fb3-vk-2, RX_CPM set) at the head e43ef403 and on main @ 6e1521a7: 11 pass at both
    (test_device_policy.py, test_dump_readback.py, test_fsr3fi_hud_mask.py, test_image_view_retry.py,
    test_inline_write_order.py, test_pipeline_state_portable.py, test_sparse_bind_failure.py,
    test_texture_staging_publication.py, test_vulkan_clear_mip.py, test_widen_alpha.py,
    nx2/test_texture_init_barrier.py); 6 fail at both with the same first error: test_low_vram_texture_mips.py
    (srccut: "'bool low_vram_texture_mips(' is in gpu/vk/vk_texture.cpp ... more than once"), test_pass_barrier.py
    ("FAIL: vk_work.h's vkCmd* macros changed"), test_staging_burst.py ("vk_texture.cpp's arenas are no longer 64 MB:
    update this test"), test_target_reuse_memory.py (2 of its 8 tests: "'vmaGetAllocationInfo2' unexpectedly found" in
    the VMA source, and its fixture's "use of undeclared identifier 'destroy_image_later'"),
    test_texel_buffer_ownership.py (an AssertionError at its count of destroy_import_buffer() and
    test_ub_update_batch.py (srccut: "'namespace mkwvk {' is in gpu/vk/vk_work.h ... more than once"). So 20 of that
    run's 31 failures fail, all on main too, and 11 pass; none fails on this branch alone. Among those that pass:
    test_pacing_policy.py, test_frame_carry_cap60.py, test_frame_rate_cap_step.py (which compile realtime_step)
    and test_close_waits_for_save.py (which reads OpenFile).

Earlier, the first version of this change on main @ 8859673e (e49530fb): the micro-benchmark in Measurements, and a
build of the game with it (longshot.exe and longshot_vk.dll, llvm-mingw).

Still to test:

  • Windows 11, this PC (i7-9700, RTX 4060 (NVIDIA 610.88)): this head and its base main @ 6e1521a7, warmed and
    interleaved, the same settings, no switches set: Castle Town's market for 60 s (average fps, 1 % lows, median and
    p99 frame times), a cold and a warm area load, a movie played with HOS_VIDEO_RGBA unset and =1, and a live change
    of the Insert menu's Resolution, expecting frame times within the runs' spread or better and the same pictures (by
    hand)
  • Linux: build the host and run python3 -I -B tests/test_vcore_fs_open.py and
    python3 -I -B tests/test_switches_read_at_start.py, expecting both to pass (by hand)
  • Linux, NVIDIA and AMD (Mesa RADV), the Steam Deck, and Windows on AMD: Castle Town's market for two minutes and an
    area load, this PR against main, expecting the same frame times as main or better and no crash (by hand, or a
    Test Farm request)

Measurements

Verdict: micro-benchmark only, not measured in play yet: a getenv of a switch that is not set took 3253 ns with
an environment of 136 variables, against 1.34 ns for the kept value. That is the lookup alone, not a file open, a
present, a movie picture or an upload, and nothing here shows a gain in the game.

Setup: Windows 11, i7-9700, llvm-mingw clang 23.1.5, -O2 -march=native as the host is built; one UCRT getenv of a
switch the game does not set, in the benchmark's own process (the job queue's environment, 136 variables), against a
static read; 21 interleaved rounds, the median and the rounds' range, in one job of the PC's job queue
(microbench.py getenv). Measured on main @ 8859673e with the first version of this change (e49530fb), not again
on this head; the kept value is a plain static read in both.

Before: main @ 8859673e After: this PR @ e49530fb (the same change on 8859673e)
a switch's read, ns a call (micro-benchmark: median of 21 rounds, range) 3253.10 (3197.40 to 3296.25), getenv 1.34 (1.24 to 1.54), the kept value
a switch's read, 136 variables           getenv (main)  median  3253.10 ns  (rounds 3197.40 to 3296.25)
a switch's read, 136 variables           read once (PR) median     1.34 ns  (rounds 1.24 to 1.54)

Risks

A switch set or changed while the game runs is no longer seen: the three host switches are read once, at the start,
after longshot_env.txt; the host sets its environment once, at start-up, and no HOS_AB reader names these four, so
a run sees the same values as before. HOS_RES_SCALE's value is stored into the fixed path's scale at every present
while it is set (the same value each time), where it was stored once, at the first present. A revert is enough; players notice
nothing (no saves, longshot_options.ini or caches change).

Checklist

Ready for review

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

When it applies

  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary Four switches were looked up in the environment every time the code that reads them ran, and the C runtime's `getenv` walks the whole environment at each call: - `HOS_NO_MOVIES` at every `nn::fs::OpenFile` that opens a file for reading (`host/nn_fs.c`); - `HOS_RES_SCALE` at every present while the Insert menu's Resolution row is set (`realtime_step`, `host/nn_vi.c`); - `HOS_VIDEO_RGBA` for every decoded movie picture (`queue_frame`, `host/nn_video.c`); - `RX_VK_LOG_PARTIAL` at every partial texture upload (`texture_touch`, `gpu/vk/vk_texture.cpp`). The first three are now read once at the start: `hos_fs_env`, `hos_video_env` and `hos_vi_env`, which `game_main` calls next to its `HOS_TRACE` read, once the environment is set (`longshot_env.txt`) and before the game's main thread is made; `HOS_RES_SCALE` is also parsed there, and `realtime_step` applies the kept value where it applied the looked-up one (at each present, the same value, with no first-use flag). The game's threads read the values without a lock, written before those threads exist. The renderer has no such start, so `RX_VK_LOG_PARTIAL` stays a C++ function-local `static const` (its initialisation is thread-safe), now looked up by the first partial upload only: a whole upload passes no guard. What each switch does is unchanged. (Main's `mirror_budget` already reads `RX_VK_MIRROR_MB` once; the change this comes from, d7dc45e2 on `exp/x86-asm-sync`, also did that one.) Read first: `hos_fs_env`, `hos_video_env`, `hos_vi_env` and their call in `game_main` (`host/hos_main.c`); `tests/test_vcore_fs_open.py`, which runs `OpenFile` with `HOS_NO_MOVIES` flipped after the start's read, and `tests/test_switches_read_at_start.py`. ## Testing **Tested:** Windows 11, i7-9700, RTX 4060 (NVIDIA 610.88), llvm-mingw clang 23.1.5; game-free checks and a micro-benchmark only. This change has not run in the game on this PC yet (Still to test). Each check ran in a hidden console of its own, in one job of the PC's job queue (fb-1952-4), on this branch rebased onto `main` @ 6e1521a7, head e43ef403: - `python -I -B tests/test_vcore_fs_open.py`: ok, in a fresh process each for `HOS_NO_MOVIES` unset, `0`, `off`, `1` and `yes`, the switch flipped after the start's read: the movies follow the value at the start. It fails at the checks' commit 641ace07 (no start read yet), and on three wrong caches written into copies of `host/nn_fs.c` (0 taken for not yet read, read at the first movie, read at the first `OpenFile`). - `python -I -B tests/test_switches_read_at_start.py`: ok (the three calls in `game_main` before the game's threads, no read left in `OpenFile`, `queue_frame` or `realtime_step`, `RX_VK_LOG_PARTIAL` inside the partial branch; the Resolution block with `HOS_RES_SCALE` unset, `0.5` and empty, flipped after the start's read, and two live menu changes without it). It fails at 641ace07. - `host/nn_fs.c`, `host/nn_vi.c`, `host/nn_video.c`, `host/hos_main.c` and `gpu/vk/vk_texture.cpp` compiled to objects with the build's own commands (llvm-mingw, not linked; the game was not built or run). - `python -I -B tests/run_all.py --strict --changed origin/main` (the checks that read a changed file, 8 at once): 132 passed, 31 failed, 12 skipped. 14 of the 31 fail on `main` @ 6e1521a7 too, run by name in the PC's job queue (fb-1952-2 and fb-1952-3): `test_crash_dialog.py`, `test_crash_record.py`, `test_dev_packs.py`, `test_display_startup_failure.py`, `test_host_guest_writes.py`, `test_libc_hooks.py`, `test_lift_cache.py`, `test_linux_pressure.py`, `test_mods_list.py`, `test_perf_report.py`, `test_profiling_mode.py`, `test_readback_timeout_source.py`, `test_slow_frames.py`, `test_vcore_escape.py`. The other 17 compiled nothing in that run nor in the runs on `main` (no Vulkan headers on the jobs' path: "not found: vulkan_headers (--strict)"). Rerun with the headers (job fb3-vk-2, `RX_CPM` set) at the head e43ef403 and on `main` @ 6e1521a7: 11 pass at both (`test_device_policy.py`, `test_dump_readback.py`, `test_fsr3fi_hud_mask.py`, `test_image_view_retry.py`, `test_inline_write_order.py`, `test_pipeline_state_portable.py`, `test_sparse_bind_failure.py`, `test_texture_staging_publication.py`, `test_vulkan_clear_mip.py`, `test_widen_alpha.py`, `nx2/test_texture_init_barrier.py`); 6 fail at both with the same first error: `test_low_vram_texture_mips.py` (srccut: "'bool low_vram_texture_mips(' is in gpu/vk/vk_texture.cpp ... more than once"), `test_pass_barrier.py` ("FAIL: vk_work.h's vkCmd* macros changed"), `test_staging_burst.py` ("vk_texture.cpp's arenas are no longer 64 MB: update this test"), `test_target_reuse_memory.py` (2 of its 8 tests: "'vmaGetAllocationInfo2' unexpectedly found" in the VMA source, and its fixture's "use of undeclared identifier 'destroy_image_later'"), `test_texel_buffer_ownership.py` (an `AssertionError` at its count of `destroy_import_buffer(`) and `test_ub_update_batch.py` (srccut: "'namespace mkwvk {' is in gpu/vk/vk_work.h ... more than once"). So 20 of that run's 31 failures fail, all on `main` too, and 11 pass; none fails on this branch alone. Among those that pass: `test_pacing_policy.py`, `test_frame_carry_cap60.py`, `test_frame_rate_cap_step.py` (which compile `realtime_step`) and `test_close_waits_for_save.py` (which reads `OpenFile`). Earlier, the first version of this change on `main` @ 8859673e (e49530fb): the micro-benchmark in Measurements, and a build of the game with it (`longshot.exe` and `longshot_vk.dll`, llvm-mingw). **Still to test:** - Windows 11, this PC (i7-9700, RTX 4060 (NVIDIA 610.88)): this head and its base `main` @ 6e1521a7, warmed and interleaved, the same settings, no switches set: Castle Town's market for 60 s (average fps, 1 % lows, median and p99 frame times), a cold and a warm area load, a movie played with `HOS_VIDEO_RGBA` unset and `=1`, and a live change of the Insert menu's Resolution, expecting frame times within the runs' spread or better and the same pictures (by hand) - Linux: build the host and run `python3 -I -B tests/test_vcore_fs_open.py` and `python3 -I -B tests/test_switches_read_at_start.py`, expecting both to pass (by hand) - Linux, NVIDIA and AMD (Mesa RADV), the Steam Deck, and Windows on AMD: Castle Town's market for two minutes and an area load, this PR against `main`, expecting the same frame times as `main` or better and no crash (by hand, or a Test Farm request) ## Measurements **Verdict:** micro-benchmark only, not measured in play yet: a `getenv` of a switch that is not set took 3253 ns with an environment of 136 variables, against 1.34 ns for the kept value. That is the lookup alone, not a file open, a present, a movie picture or an upload, and nothing here shows a gain in the game. Setup: Windows 11, i7-9700, llvm-mingw clang 23.1.5, `-O2 -march=native` as the host is built; one UCRT `getenv` of a switch the game does not set, in the benchmark's own process (the job queue's environment, 136 variables), against a static read; 21 interleaved rounds, the median and the rounds' range, in one job of the PC's job queue (`microbench.py getenv`). Measured on `main` @ 8859673e with the first version of this change (e49530fb), not again on this head; the kept value is a plain static read in both. | | Before: main @ 8859673e | After: this PR @ e49530fb (the same change on 8859673e) | |---|---|---| | a switch's read, ns a call (micro-benchmark: median of 21 rounds, range) | 3253.10 (3197.40 to 3296.25), `getenv` | 1.34 (1.24 to 1.54), the kept value | ``` a switch's read, 136 variables getenv (main) median 3253.10 ns (rounds 3197.40 to 3296.25) a switch's read, 136 variables read once (PR) median 1.34 ns (rounds 1.24 to 1.54) ``` ## Risks A switch set or changed while the game runs is no longer seen: the three host switches are read once, at the start, after `longshot_env.txt`; the host sets its environment once, at start-up, and no `HOS_AB` reader names these four, so a run sees the same values as before. `HOS_RES_SCALE`'s value is stored into the fixed path's scale at every present while it is set (the same value each time), where it was stored once, at the first present. A revert is enough; players notice nothing (no saves, `longshot_options.ini` or caches change). ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). - [ ] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
perf(host): four switches read on per-call paths are read once
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
c9d74d7845
HOS_NO_MOVIES (every OpenFile), HOS_RES_SCALE (every present while the Resolution row is set), HOS_VIDEO_RGBA (every
decoded movie picture) and RX_VK_LOG_PARTIAL (every partial texture upload) were a getenv at each call; the C runtime's
getenv walks the whole environment. The host sets its environment once at start-up, so each is now read at its first
use and kept. tests/test_vcore_fs_open.py checks HOS_NO_MOVIES is read once.

From d7dc45e2 on exp/x86-asm-sync; main's mirror_budget already reads RX_VK_MIRROR_MB once.

Assisted-by: Claude Code
BeanBot left a comment

Recommendation: Request changes. The file-open and movie-decode caches introduce data races, and the texture change adds work to whole uploads. The isolated lookup is faster, but the PR has yet to show a gain in play.

The PR caches four environment switches to cut CPU work during file opens, presents, movie decoding and texture uploads. The existing defaults are appropriate, but the caches need safe initialization, and the resolution override can use one lookup and one parse.

Does it help: Unproven. The author's Windows 11 UCRT microbenchmark on an i7-9700 with 136 environment variables reported a median of 3,253.10 ns per unset lookup versus 1.34 ns for a cached read over 21 interleaved rounds, using 8859673e and e49530fb. It measures the isolated lookup. There are no paired in-game results for frame times, file loading, movie decoding or texture uploads on the reviewed base.
Other systems: Concurrent asset readers and separate movie decoders share the new host caches on Windows and Linux. The resolution path still reads the live Insert menu setting when the override is absent. The texture change is shared across Vulkan vendors and replay modes, including RADV and Steam Deck. It affects CPU-side diagnostic work on the upload path. The diff changes no upload sizes, decoder allocation sizes, saves, settings format or renderer API.
Switches: No switches added or removed. HOS_NO_MOVIES defaults to playing movies. HOS_RES_SCALE defaults to following the Insert menu, and presence still takes precedence. HOS_VIDEO_RGBA defaults to deferring RGBA conversion for NV12/YUV420. RX_VK_LOG_PARTIAL defaults to logging off. All four defaults are appropriate for a startup configuration and already appear in gpu/vk/switches.def. The diff freezes their values for the run. The startup loader and HOS_AB call sites show no supported live update for these four.

Reviewed: c9d74d7845 against 2e1f6c32d3: Read the complete diff, commit, AGENTS.md, CONTRIBUTING.md, Forgejo template, developer standards and tests/test_vcore_fs_open.py. Read the changed C and C++ functions in full, their relevant callers, locks, startup environment loading, resolution readers, switch rows and test runner integration. Other code in those source files was outside the review path. Skimmed the author's run summaries. The raw benchmark and CI logs were unavailable, and docs/review-checklist.md was absent. The PR supplied no comments or prior reviews.; nothing run (a code review).
Checked and fine:

  • One topic in a Conventional Commit with an Assisted-by trailer. The diff contains no game-derived data, build outputs, generated files, third-party changes or API changes requiring a version bump.
  • The OpenFile extension check and virtual-core restoration are preserved. The new assertion would catch restoration of an unconditional per-call lookup on the enabled path.
  • The renderer's C++ local static has thread-safe initialization with the supported build flags. The texture upload ranges and failure handling are untouched.
  • The fixture controls both switches it reads, uses platform-specific environment setters, and receives the selected C++ compiler from the suite runner.

Blocking (to change before merge)

  1. host/nn_fs.c:394: Parallel asset opens can reach the plain no_movies cache together. OpenFile has released the virtual core and host_path has released the mount lock by this point. Two first reads can race even when both store zero. Initialize the flag after startup environment loading and before guest threads, or use a thread-safe once operation. Keep the write-only path out of lazy initialization.
  2. host/nn_video.c:428: The force_rgba static is shared across decoder instances, but dec_acquire holds only that decoder's lock. Two movie streams producing their first frames on different guest threads can race on the same flag. Initialize it before guest threads start or use a thread-safe once operation.
  3. host/nn_vi.c:477: The first present still checks HOS_RES_SCALE again in the read_scale block and looks it up a third time when set. It also adds a mutable first-use flag on the guest caller's path outside the renderer lock. Read and parse the override once during startup, then use its presence to gate live menu updates and apply its value at the existing point.
  4. gpu/vk/vk_texture.cpp:3354: A first whole texture upload can now initialize the diagnostic flag and call getenv. Subsequent whole uploads also encounter the static guard, although only partial uploads use the result. Move the cached lookup behind the partial check.
  5. tests/test_vcore_fs_open.py:134: The test only caches an enabled value and changes it after the first movie open. A cache that treats zero as uninitialized, or initializes only on the first movie, passes. In fresh processes, start with each value, open an ordinary file, flip the switch, then check that the movie follows the initial value. Check that the environment change succeeds.

Waiting on the author (a run, a measurement or a decision; no edit does it)

  • The microbenchmark provides no in-game gain or first-use cost. Compare the revised head and its base in warm, interleaved runs with matching settings. Report average FPS, 1% lows and median and p99 frame times, plus cold and warm asset-load timings and decode and upload timings in scenes that exercise those paths. Include a live Resolution change and both movie conversion modes in the checks.
  • The PR opened before the required author game run. The reported Windows checks are from an earlier rebase, and Linux build, full-suite and head CI results are still missing. Record the owner-PC run, verify the revised head on Windows and Linux, and post the affected Tier 1 results, including Windows AMD, Linux NVIDIA and RADV, and Steam Deck.

Testing: Read-only review. The author reports that the focused Windows test passed on b359f827. The changed-source run reported 83 passed, 9 failed and 5 skipped, with the same nine failures individually reproduced on fc4a6769. The author also reports an earlier Windows build. Linux and in-game runs were pending, and there were no tester comments.
Overlaps and merge order: No overlapping pull request found in the checkout or supplied discussion. The cited experimental commit is the source of the change. The forge's open PR list was unavailable.


Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The file-open and movie-decode caches introduce data races, and the texture change adds work to whole uploads. The isolated lookup is faster, but the PR has yet to show a gain in play. The PR caches four environment switches to cut CPU work during file opens, presents, movie decoding and texture uploads. The existing defaults are appropriate, but the caches need safe initialization, and the resolution override can use one lookup and one parse. **Does it help:** Unproven. The author's Windows 11 UCRT microbenchmark on an i7-9700 with 136 environment variables reported a median of 3,253.10 ns per unset lookup versus 1.34 ns for a cached read over 21 interleaved rounds, using 8859673e and e49530fb. It measures the isolated lookup. There are no paired in-game results for frame times, file loading, movie decoding or texture uploads on the reviewed base. **Other systems:** Concurrent asset readers and separate movie decoders share the new host caches on Windows and Linux. The resolution path still reads the live Insert menu setting when the override is absent. The texture change is shared across Vulkan vendors and replay modes, including RADV and Steam Deck. It affects CPU-side diagnostic work on the upload path. The diff changes no upload sizes, decoder allocation sizes, saves, settings format or renderer API. **Switches:** No switches added or removed. HOS_NO_MOVIES defaults to playing movies. HOS_RES_SCALE defaults to following the Insert menu, and presence still takes precedence. HOS_VIDEO_RGBA defaults to deferring RGBA conversion for NV12/YUV420. RX_VK_LOG_PARTIAL defaults to logging off. All four defaults are appropriate for a startup configuration and already appear in gpu/vk/switches.def. The diff freezes their values for the run. The startup loader and HOS_AB call sites show no supported live update for these four. **Reviewed:** c9d74d784542 against 2e1f6c32d30e: Read the complete diff, commit, AGENTS.md, CONTRIBUTING.md, Forgejo template, developer standards and tests/test_vcore_fs_open.py. Read the changed C and C++ functions in full, their relevant callers, locks, startup environment loading, resolution readers, switch rows and test runner integration. Other code in those source files was outside the review path. Skimmed the author's run summaries. The raw benchmark and CI logs were unavailable, and docs/review-checklist.md was absent. The PR supplied no comments or prior reviews.; nothing run (a code review). **Checked and fine:** - One topic in a Conventional Commit with an Assisted-by trailer. The diff contains no game-derived data, build outputs, generated files, third-party changes or API changes requiring a version bump. - The OpenFile extension check and virtual-core restoration are preserved. The new assertion would catch restoration of an unconditional per-call lookup on the enabled path. - The renderer's C++ local static has thread-safe initialization with the supported build flags. The texture upload ranges and failure handling are untouched. - The fixture controls both switches it reads, uses platform-specific environment setters, and receives the selected C++ compiler from the suite runner. **Blocking** (to change before merge) 1. host/nn_fs.c:394: Parallel asset opens can reach the plain no_movies cache together. OpenFile has released the virtual core and host_path has released the mount lock by this point. Two first reads can race even when both store zero. Initialize the flag after startup environment loading and before guest threads, or use a thread-safe once operation. Keep the write-only path out of lazy initialization. 2. host/nn_video.c:428: The force_rgba static is shared across decoder instances, but dec_acquire holds only that decoder's lock. Two movie streams producing their first frames on different guest threads can race on the same flag. Initialize it before guest threads start or use a thread-safe once operation. 3. host/nn_vi.c:477: The first present still checks HOS_RES_SCALE again in the read_scale block and looks it up a third time when set. It also adds a mutable first-use flag on the guest caller's path outside the renderer lock. Read and parse the override once during startup, then use its presence to gate live menu updates and apply its value at the existing point. 4. gpu/vk/vk_texture.cpp:3354: A first whole texture upload can now initialize the diagnostic flag and call getenv. Subsequent whole uploads also encounter the static guard, although only partial uploads use the result. Move the cached lookup behind the partial check. 5. tests/test_vcore_fs_open.py:134: The test only caches an enabled value and changes it after the first movie open. A cache that treats zero as uninitialized, or initializes only on the first movie, passes. In fresh processes, start with each value, open an ordinary file, flip the switch, then check that the movie follows the initial value. Check that the environment change succeeds. **Waiting on the author** (a run, a measurement or a decision; no edit does it) - The microbenchmark provides no in-game gain or first-use cost. Compare the revised head and its base in warm, interleaved runs with matching settings. Report average FPS, 1% lows and median and p99 frame times, plus cold and warm asset-load timings and decode and upload timings in scenes that exercise those paths. Include a live Resolution change and both movie conversion modes in the checks. - The PR opened before the required author game run. The reported Windows checks are from an earlier rebase, and Linux build, full-suite and head CI results are still missing. Record the owner-PC run, verify the revised head on Windows and Linux, and post the affected Tier 1 results, including Windows AMD, Linux NVIDIA and RADV, and Steam Deck. **Testing:** Read-only review. The author reports that the focused Windows test passed on b359f827. The changed-source run reported 83 passed, 9 failed and 5 skipped, with the same nine failures individually reproduced on fc4a6769. The author also reports an earlier Windows build. Linux and in-game runs were pending, and there were no tester comments. **Overlaps and merge order:** No overlapping pull request found in the checkout or supplied discussion. The cited experimental commit is the source of the change. The forge's open PR list was unavailable. --- <sub>Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -3352,3 +3352,3 @@
return tex;
}
if (partial && env_on("RX_VK_LOG_PARTIAL")) {
static const bool log_partial = env_on("RX_VK_LOG_PARTIAL"); // (read once: it was a getenv at every partial upload)
Member

Whole uploads now hit the static guard and can initialize it. Put the cached lookup behind the partial check so whole uploads skip the diagnostic.

Whole uploads now hit the static guard and can initialize it. Put the cached lookup behind the partial check so whole uploads skip the diagnostic.
host/nn_fs.c Outdated
@ -393,0 +391,4 @@
game goes on without them (decoded by nn_video.c otherwise). Read once, at the first OpenFile that gets here: it
holds for the run, and the C runtime's getenv walks the whole environment at every call */
static int no_movies = -1;
if (no_movies < 0) no_movies = env_on("HOS_NO_MOVIES");
Member

Concurrent opens can reach this plain static after releasing the virtual core and mount lock. Equal stores still race. Initialize it before guest threads or use a thread-safe once operation.

Concurrent opens can reach this plain static after releasing the virtual core and mount lock. Equal stores still race. Initialize it before guest threads or use a thread-safe once operation.
host/nn_vi.c Outdated
@ -475,1 +475,3 @@
below stays over it) */
below stays over it. Whether it is set is read once: it was a getenv at every present while the row is set) */
static int res_env = -1;
if (res_env < 0) res_env = getenv("HOS_RES_SCALE") != NULL;
Member

The first present still looks up this variable two or three times. Parse it once during startup and use that snapshot for both menu precedence and the override value.

The first present still looks up this variable two or three times. Parse it once during startup and use that snapshot for both menu precedence and the override value.
host/nn_video.c Outdated
@ -427,2 +427,2 @@
const char *rgba_env = getenv("HOS_VIDEO_RGBA");
const int force_rgba = rgba_env && !env_value_off(rgba_env);
static int force_rgba = -1; /* (read once: it was a getenv for every decoded picture) */
if (force_rgba < 0) { const char *rgba_env = getenv("HOS_VIDEO_RGBA"); force_rgba = rgba_env && !env_value_off(rgba_env); }
Member

Each decoder holds its own lock. Two decoders can race when setting this shared flag. Initialize it before decoding can start or use a thread-safe once operation.

Each decoder holds its own lock. Two decoders can race when setting this shared flag. Initialize it before decoding can start or use a thread-safe once operation.
@ -131,2 +131,4 @@
check(r == R_PATH_NOT_FOUND && held == 1 && held_in_create == -1, "a movie left out (HOS_NO_MOVIES): the core back");
set_env("HOS_NO_MOVIES", NULL);
r = open_file("rom:/Movie/b.webm", 1, 1);
check(r == R_PATH_NOT_FOUND && held_in_create == -1, "HOS_NO_MOVIES is read once, not at every OpenFile");
Member

This passes with a cache that only remembers true or starts on the first movie. In two fresh processes, flip the switch after the first ordinary read and verify both initial values.

This passes with a cache that only remembers true or starts on the first movie. In two fresh processes, flip the switch after the first ordinary read and verify both initial values.
futondestroyer left a comment

Recommendation: Request changes. Concurrent file opens and movie decoders can race while initializing their new process-wide C flags. Initialize both after startup environment loading and before guest threads start, or use synchronized one-time initialization.

  • host/nn_fs.c:394 runs after OpenFile releases its virtual core and host_path releases the mount lock. Two ordinary asset opens can both write the cache even with the switch unset. If the fix keeps lazy initialization, preserve the read-only guard so a write-capable open on a writable mount skips this lookup. File-open discussion
  • host/nn_video.c:428 shares the flag among separate decoders. Two first-frame calls can hold different d->lock instances and still write the same flag. This covers the FFmpeg and the AV1 callback paths. The predicate should preserve the existing mode selection. Decoder discussion

Does it help? Unproven in play. The author's Windows microbenchmark on earlier revisions reports median 3,253.10 ns for an unset lookup and 1.34 ns for a cached read over 21 interleaved rounds with 136 environment variables. Compare the corrected head and its base in interleaved gameplay runs that exercise presents, asset loading, movie decoding and texture uploads. Include average FPS, 1% lows, median and p99 frame times, and the relevant load, decode and upload timings.

Other findings

  • The first present now looks up HOS_RES_SCALE twice when absent and three times when present. Derive presence and the parsed override from one read. Keep live Resolution updates when the override is absent, and preserve the current presence rule for an empty value on Linux. Resolution discussion
  • With partial false, reaching texture_touch's upload block now runs the logging initializer on its first visit and checks the guard thereafter. Leave the cached lookup inside the partial branch so initial and whole uploads skip it. The existing upload ranges and failure handling are preserved. Texture discussion
  • The OpenFile test exercises the enabled cache in one process. A cache that only remembers true or initializes at the first movie could pass. For a lazy implementation, cover both initial values in fresh processes and change the environment after the ordinary read, before either process opens a movie. Test discussion

Switches and scope

The default is to find movies, follow the live Resolution menu, defer RGBA conversion for NV12/YUV420 frames and leave partial-upload logging off. All four switches already have rows. Both host platforms and the shared renderer path are in scope. This diff leaves the save format, renderer API and generated files alone.

Review and testing

Reviewed all five changed files and their relevant call paths at c9d74d784542 against 2e1f6c32d30e. The author reports 83 passing, 9 baseline-matching failures and 5 skips on the prior Windows revision, plus the focused OpenFile pass. The exact head still needs the author gameplay run, the applicable Windows and Linux checks, and affected Tier 1 coverage. Forgejo showed the description check passing and source jobs waiting on required conditions. Beanstalk showed no reports. No overlap requiring a merge order was found among the inspected branches.

**Recommendation: Request changes.** Concurrent file opens and movie decoders can race while initializing their new process-wide C flags. Initialize both after startup environment loading and before guest threads start, or use synchronized one-time initialization. - `host/nn_fs.c:394` runs after `OpenFile` releases its virtual core and `host_path` releases the mount lock. Two ordinary asset opens can both write the cache even with the switch unset. If the fix keeps lazy initialization, preserve the read-only guard so a write-capable open on a writable mount skips this lookup. [File-open discussion](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1952#issuecomment-61933) - `host/nn_video.c:428` shares the flag among separate decoders. Two first-frame calls can hold different `d->lock` instances and still write the same flag. This covers the FFmpeg and the AV1 callback paths. The predicate should preserve the existing mode selection. [Decoder discussion](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1952#issuecomment-61934) **Does it help?** Unproven in play. The author's Windows microbenchmark on earlier revisions reports median 3,253.10 ns for an unset lookup and 1.34 ns for a cached read over 21 interleaved rounds with 136 environment variables. Compare the corrected head and its base in interleaved gameplay runs that exercise presents, asset loading, movie decoding and texture uploads. Include average FPS, 1% lows, median and p99 frame times, and the relevant load, decode and upload timings. **Other findings** - The first present now looks up `HOS_RES_SCALE` twice when absent and three times when present. Derive presence and the parsed override from one read. Keep live Resolution updates when the override is absent, and preserve the current presence rule for an empty value on Linux. [Resolution discussion](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1952#issuecomment-61935) - With `partial` false, reaching `texture_touch`'s upload block now runs the logging initializer on its first visit and checks the guard thereafter. Leave the cached lookup inside the partial branch so initial and whole uploads skip it. The existing upload ranges and failure handling are preserved. [Texture discussion](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1952#issuecomment-61936) - The OpenFile test exercises the enabled cache in one process. A cache that only remembers true or initializes at the first movie could pass. For a lazy implementation, cover both initial values in fresh processes and change the environment after the ordinary read, before either process opens a movie. [Test discussion](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1952#issuecomment-61937) **Switches and scope** The default is to find movies, follow the live Resolution menu, defer RGBA conversion for NV12/YUV420 frames and leave partial-upload logging off. All four switches already have rows. Both host platforms and the shared renderer path are in scope. This diff leaves the save format, renderer API and generated files alone. **Review and testing** Reviewed all five changed files and their relevant call paths at `c9d74d784542` against `2e1f6c32d30e`. The author reports 83 passing, 9 baseline-matching failures and 5 skips on the prior Windows revision, plus the focused OpenFile pass. The exact head still needs the author gameplay run, the applicable Windows and Linux checks, and affected Tier 1 coverage. Forgejo showed the description check passing and source jobs waiting on required conditions. Beanstalk showed no reports. No overlap requiring a merge order was found among the inspected branches.
host/nn_fs.c Outdated
@ -393,0 +392,4 @@
holds for the run, and the C runtime's getenv walks the whole environment at every call */
static int no_movies = -1;
if (no_movies < 0) no_movies = env_on("HOS_NO_MOVIES");
if (!want_write && no_movies) {
Member

On a writable mount, a mode with write or append bits reaches the newly hoisted cache lookup, though the base short-circuited before the switch lookup. If initialization stays lazy after the race fix, put it under the read-only guard.

On a writable mount, a mode with write or append bits reaches the newly hoisted cache lookup, though the base short-circuited before the switch lookup. If initialization stays lazy after the race fix, put it under the read-only guard.
host/nn_vi.c Outdated
@ -476,2 +477,3 @@
if (res_env < 0) res_env = getenv("HOS_RES_SCALE") != NULL;
const int scale = rx_option(3, 0);
if (scale > 0 && !getenv("HOS_RES_SCALE")) {
if (scale > 0 && !res_env) {
Member

Preserve the distinction between unset and empty when consolidating the reads. Linux can retain an empty variable, and the existing presence test treats it as an override. With the override absent, verify that a second live menu change still takes effect.

Preserve the distinction between unset and empty when consolidating the reads. Linux can retain an empty variable, and the existing presence test treats it as an override. With the override absent, verify that a second live menu change still takes effect.
siantm force-pushed perf/switches-read-once from c9d74d7845
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to e43ef40379
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
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / 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
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 16s
2026-11-21 03:22:30 +00:00
Compare
Author
Contributor

Thanks for the review. The branch is rebased onto main @ 6e1521a7 (the PR's own commit unchanged, git range-diff shows it equal), with two new commits on top: 641ace07 (the checks) and e43ef403 (the change). The checks ran in the PC's job queue (fb-1952-4): both new checks fail at 641ace07 and pass at e43ef403.

  • Point 1 (no_movies raced by parallel opens): fixed in e43ef403. HOS_NO_MOVIES is read by hos_fs_env, which game_main calls next to its HOS_TRACE read, after longshot_env.txt and before the game's main thread is made; OpenFile only reads the kept value, and no path of it looks the switch up, the write path included.
  • Point 2 (force_rgba shared by decoders): fixed in e43ef403 the same way (hos_video_env); queue_frame no longer reads the environment.
  • Point 3 (HOS_RES_SCALE looked up 2-3 times, a first-use flag): fixed in e43ef403. hos_vi_env reads and parses it once at the start (presence != NULL, as before); realtime_step has no first-use flag and no lookup: the kept value is applied where it was (stored at each present while it is set), and the Insert menu's Resolution only when it is not set. tests/test_switches_read_at_start.py runs that block with hos_vi_env in fresh processes (unset, 0.5, empty), the variable flipped after the start's read: the override holds, and without it two live menu changes both take effect.
  • Point 4 (the guard on whole uploads): fixed in e43ef403: the static const lookup is inside if (partial), so a whole upload neither initialises nor passes it.
  • Point 5 (the test): fixed in 641ace07. tests/test_vcore_fs_open.py now runs a fresh process for each of HOS_NO_MOVIES unset, 0, off, 1 and yes (the value checked inside the process), flips the switch right after the start's read and checks that the flip took, then opens an ordinary file and two movies, which must follow the value at the start. That is stricter than flipping after the first ordinary open: a read at the first OpenFile fails too. Run against three wrong caches written into copies of nn_fs.c (0 taken for not yet read, read at the first movie, read at the first OpenFile), it fails on each. tests/test_switches_read_at_start.py checks the three calls' place in game_main, that OpenFile, queue_frame and realtime_step no longer read these switches, and that RX_VK_LOG_PARTIAL is looked up inside the partial branch only.

Also run at e43ef403: the five changed translation units (nn_fs.c, nn_vi.c, nn_video.c, hos_main.c, vk_texture.cpp) compiled with the build's own commands, llvm-mingw, to objects (not linked); tests/run_all.py --strict --changed origin/main: 132 passed, 31 failed, 12 skipped; the 31 fail on main @ 6e1521a7 too, run by name (fb-1952-2, fb-1952-3), none on this branch alone.

Waiting on me, not done yet (listed in Still to test): this head has not run in the game, so there are no frame-time, load, decode or upload timings. The only figure is the micro-benchmark of the lookup alone; nothing shows a gain in play yet. The paired runs (head and its base, warmed and interleaved, with a live Resolution change and both movie conversion modes), the Linux build and tests, the Tier 1 runs and CI on this head are pending.

Thanks for the review. The branch is rebased onto `main` @ 6e1521a7 (the PR's own commit unchanged, `git range-diff` shows it equal), with two new commits on top: 641ace07 (the checks) and e43ef403 (the change). The checks ran in the PC's job queue (fb-1952-4): both new checks fail at 641ace07 and pass at e43ef403. - [Point 1](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1952#issuecomment-61933) (`no_movies` raced by parallel opens): fixed in e43ef403. `HOS_NO_MOVIES` is read by `hos_fs_env`, which `game_main` calls next to its `HOS_TRACE` read, after `longshot_env.txt` and before the game's main thread is made; `OpenFile` only reads the kept value, and no path of it looks the switch up, the write path included. - [Point 2](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1952#issuecomment-61934) (`force_rgba` shared by decoders): fixed in e43ef403 the same way (`hos_video_env`); `queue_frame` no longer reads the environment. - [Point 3](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1952#issuecomment-61935) (`HOS_RES_SCALE` looked up 2-3 times, a first-use flag): fixed in e43ef403. `hos_vi_env` reads and parses it once at the start (presence `!= NULL`, as before); `realtime_step` has no first-use flag and no lookup: the kept value is applied where it was (stored at each present while it is set), and the Insert menu's Resolution only when it is not set. `tests/test_switches_read_at_start.py` runs that block with `hos_vi_env` in fresh processes (unset, `0.5`, empty), the variable flipped after the start's read: the override holds, and without it two live menu changes both take effect. - [Point 4](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1952#issuecomment-61936) (the guard on whole uploads): fixed in e43ef403: the `static const` lookup is inside `if (partial)`, so a whole upload neither initialises nor passes it. - [Point 5](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1952#issuecomment-61937) (the test): fixed in 641ace07. `tests/test_vcore_fs_open.py` now runs a fresh process for each of `HOS_NO_MOVIES` unset, `0`, `off`, `1` and `yes` (the value checked inside the process), flips the switch right after the start's read and checks that the flip took, then opens an ordinary file and two movies, which must follow the value at the start. That is stricter than flipping after the first ordinary open: a read at the first `OpenFile` fails too. Run against three wrong caches written into copies of `nn_fs.c` (0 taken for not yet read, read at the first movie, read at the first `OpenFile`), it fails on each. `tests/test_switches_read_at_start.py` checks the three calls' place in `game_main`, that `OpenFile`, `queue_frame` and `realtime_step` no longer read these switches, and that `RX_VK_LOG_PARTIAL` is looked up inside the partial branch only. Also run at e43ef403: the five changed translation units (`nn_fs.c`, `nn_vi.c`, `nn_video.c`, `hos_main.c`, `vk_texture.cpp`) compiled with the build's own commands, llvm-mingw, to objects (not linked); `tests/run_all.py --strict --changed origin/main`: 132 passed, 31 failed, 12 skipped; the 31 fail on `main` @ 6e1521a7 too, run by name (fb-1952-2, fb-1952-3), none on this branch alone. Waiting on me, not done yet (listed in Still to test): this head has not run in the game, so there are no frame-time, load, decode or upload timings. The only figure is the micro-benchmark of the lookup alone; nothing shows a gain in play yet. The paired runs (head and its base, warmed and interleaved, with a live Resolution change and both movie conversion modes), the Linux build and tests, the Tier 1 runs and CI on this head are pending.
Author
Contributor

@futondestroyer thanks for the review (62736). Fixed in e43ef403 (checks in 641ace07), rebased onto main @ 6e1521a7:

  • The two races: HOS_NO_MOVIES and HOS_VIDEO_RGBA are no longer initialised lazily. hos_fs_env and hos_video_env read them in game_main after longshot_env.txt and before the game's main thread is made; OpenFile and queue_frame (FFmpeg's and the AV1 callback's path both go through it) only read the kept values. HOS_VIDEO_RGBA's predicate is env_on, which is the same test as before (set && !env_value_off).
  • 62734 (a write-capable open reaching the lookup): with the read at the start, OpenFile does no lookup on any path, the write path included.
  • 62735 and the Resolution finding: hos_vi_env takes presence and the parsed value from one getenv at the start, presence being != NULL as before, so an empty value still counts as set. realtime_step has no lookup or first-use flag left. tests/test_switches_read_at_start.py compiles that function and realtime_step's Resolution block and runs them in fresh processes (unset, 0.5, empty), flipping the variable after the start's read. With the override absent, two later live menu changes both take effect. On this Windows PC the empty value reached the process and counted as set (the override, 0, held over the menu); the Linux run is pending.
  • Texture and test findings: as in my reply to BeanBot's points 4 and 5 (the lookup is inside if (partial); fresh processes for unset, 0, off, 1 and yes, with the flip checked).

Pending on my side: the interleaved gameplay runs, the Linux checks, Tier 1 and CI on this head.

@futondestroyer thanks for the review ([62736](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1952#issuecomment-62736)). Fixed in e43ef403 (checks in 641ace07), rebased onto `main` @ 6e1521a7: - The two races: `HOS_NO_MOVIES` and `HOS_VIDEO_RGBA` are no longer initialised lazily. `hos_fs_env` and `hos_video_env` read them in `game_main` after `longshot_env.txt` and before the game's main thread is made; `OpenFile` and `queue_frame` (FFmpeg's and the AV1 callback's path both go through it) only read the kept values. `HOS_VIDEO_RGBA`'s predicate is `env_on`, which is the same test as before (`set && !env_value_off`). - [62734](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1952#issuecomment-62734) (a write-capable open reaching the lookup): with the read at the start, `OpenFile` does no lookup on any path, the write path included. - [62735](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1952#issuecomment-62735) and the Resolution finding: `hos_vi_env` takes presence and the parsed value from one `getenv` at the start, presence being `!= NULL` as before, so an empty value still counts as set. `realtime_step` has no lookup or first-use flag left. `tests/test_switches_read_at_start.py` compiles that function and realtime_step's Resolution block and runs them in fresh processes (unset, `0.5`, empty), flipping the variable after the start's read. With the override absent, two later live menu changes both take effect. On this Windows PC the empty value reached the process and counted as set (the override, 0, held over the menu); the Linux run is pending. - Texture and test findings: as in my reply to BeanBot's points 4 and 5 (the lookup is inside `if (partial)`; fresh processes for unset, `0`, `off`, `1` and `yes`, with the flip checked). Pending on my side: the interleaved gameplay runs, the Linux checks, Tier 1 and CI on this head.
Author
Contributor

@Beanstalk This reads four switches once at startup instead of on every call: HOS_NO_MOVIES (each file open for reading), HOS_RES_SCALE (each present), HOS_VIDEO_RGBA (each movie frame) and one renderer switch read at each texture upload (gpu/vk/vk_texture.cpp). Behaviour must not change: movies play, a Resolution change in the Insert menu applies at once. It has not run in the game on these PCs yet. Please start from the title with its movie, then play Castle Town Market for two minutes with one area load and one change of the Insert menu's Resolution during play, the PR against main on the same PC, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. No crash or hang; the movie plays and the new resolution applies as on main; frame time p99 equal to main's or better, within the run-to-run spread.

@Beanstalk This reads four switches once at startup instead of on every call: HOS_NO_MOVIES (each file open for reading), HOS_RES_SCALE (each present), HOS_VIDEO_RGBA (each movie frame) and one renderer switch read at each texture upload (gpu/vk/vk_texture.cpp). Behaviour must not change: movies play, a Resolution change in the Insert menu applies at once. It has not run in the game on these PCs yet. Please start from the title with its movie, then play Castle Town Market for two minutes with one area load and one change of the Insert menu's Resolution during play, the PR against main on the same PC, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. No crash or hang; the movie plays and the new resolution applies as on main; frame time p99 equal to main's or better, within the run-to-run spread.
Member

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

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

The 17 renderer checks that failed with "not found: vulkan_headers (--strict)" did not compile in the earlier run (no Vulkan headers on that job's path); rerun with them in job fb3-vk-2, at the head e43ef403 and on main @ 6e1521a7: 11 pass at both and 6 fail at both with the same first error, so 20 of the 31 failures fail (all on main too); Tested's sentence and counts corrected.

The 17 renderer checks that failed with "not found: vulkan_headers (--strict)" did not compile in the earlier run (no Vulkan headers on that job's path); rerun with them in job fb3-vk-2, at the head e43ef403 and on `main` @ 6e1521a7: 11 pass at both and 6 fail at both with the same first error, so 20 of the 31 failures fail (all on `main` too); Tested's sentence and counts corrected.
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
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / 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
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 16s
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/switches-read-once:siantm-perf/switches-read-once'
git switch 'siantm-perf/switches-read-once'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 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!1952
No description provided.