perf(vk): the menu's status each frame keeps the screen's size and reads HOS_WIDE_MAX_PX and HOS_AUDIO_DEVICE once #3234
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3234
Loading…
Reference in a new issue
No description provided.
Delete branch "dyst/Longshot:perf/menu-status-main-thread"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Every frame, the game's main thread asks the Insert menu for its capabilities and the renderer for its status (the
settings service's restart check, the HDR status query, the frame's settings). Those answers work out the screen's size
and the widescreen picture's size many times a frame (every Aspect ratio value goes through
monitor_shape), and each timethey went to the system:
MonitorFromWindow+GetMonitorInfoW, or twoGetSystemMetrics, round trips into the windowsystem (~2.5 % of the frame's critical path standing in Hyrule Field);
getenv("HOS_WIDE_MAX_PX")inhos_wide_max_px/hos_wide_picture, andgetenv("HOS_AUDIO_DEVICE")in thestatus's row bits: the C runtime's lock and a walk of the whole environment, ~5 % of the main thread's samples.
The main thread is the frame's serial stretch, so its time is the frame's. This keeps the screen's size 100 ms per thread
(and per window), well inside
outputs_follow_screen's 30 presents, and reads the two variables once (they are setbefore any thread reads the environment:
game_host.chos_switch_set). In a profile of Hyrule Field the menu's pollersfell from ~10 % of the main thread's samples to under 1 %.
Read first:
gpu/vk/menu/output.cpp(screen_kept,screen_size,host_screen_size),host/hos_wide_size.h(
hos_wide_max_env),gpu/vk/menu/audio.cpp(output_forced).Testing
Tested: Windows 11 (22631), Ryzen 9 3900X, RTX 3080 (NVIDIA 621.47). These two commits over main
3b3ea2cb3ransix runs of play through
dev.py ab(Hyrule Field and Market, teleported, ~100 s each) and a profiled Hyrule Field run:every run played to its end, and in the profile the menu's pollers are under 1 % of the main thread's samples (~10 %
before).
tests/run_all.py --strict: 838 passed, 21 failed, 52 skipped (Windows, llvm-mingw,--strict). The 21 fail on main3a0f7d8f7too, in the same setup, and none reads a changed file:test_dev_update.py,test_dlssg.py,test_framegen_hdr.py,test_fsr3fi_hud_layer.py,test_fsr3fi_hudless_colour.py,test_fsr4_tune.py,test_gfx_effects.py,test_helpers_extract.py,test_lifter.py,test_longshot_ctl.py,test_native_zstd.py,test_no_game_title.py,test_no_map_reload.py,test_present_acquire_ahead.py,test_present_geometry_trace.py,test_present_held_image.py,test_present_image_free.py,test_sync_watch_event.py,test_temporal_present_bandwidth.py,test_turf_budget.py,test_ui_renderer.py. The checks that read the changed files (--changed) all pass,test_audio_output_devices.py,test_output_resolution.pyandtest_display_modes.pyamong them.Still to test:
monitor, expecting the "(monitor's)" and "(native)" marks to follow it within a moment (by hand)
(@Beanstalk play Hyrule Field on the Steam Deck and open the Insert menu's Output resolution row)
Measurements
Verdict: it helps where the game's main thread sets the pace: Hyrule Field +5.5 % fps, the game's frame 0.6 ms shorter; Market +5.4 % in a second series (the game's frame 0.65 ms shorter), after a first series at -3.0 % whose game time did not move and whose render thread drew slower in both B runs. All eight Market runs together: median 58.75 -> 59.8 fps (+1.8 %); Market's runs spread over up to ~7 fps.
Setup: Windows 11, Ryzen 9 3900X, RTX 3080 (NVIDIA 621.47); 3440 x 1440 output, Render resolution 67 %, VSync off,
uncapped (
HOS_FPS_MAX=1000), CPU-bound.dev.py abwith two runtimes, interleaved (A B A B), each run 60 s measuredafter the warm-up; the median of each run's fps. Both sides are main
3b3ea2cb3with #2235's lift change and twoprofiling-only commits; B adds exactly this PR's two commits.
3b3ea2cb3(+ #2235)ac8a6d4dc(its two commits over the same)Risks
default output size follow it a moment later;
outputs_follow_screenwaits 30 presents anyway).HOS_WIDE_MAX_PXandHOS_AUDIO_DEVICEset while the game runs are no longer seen. Nothing sets them during a run(they are start-up switches); a run started with them behaves as before.
settings.tomlor the caches.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened:tests/test_audio_output_devices.pyset
HOS_AUDIO_DEVICEhalfway through its fixture's run; the fixture now runs a second time with it set before itstarts, as a run's switches are, and asserts the same.
Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
The Insert menu's capabilities and the renderer's status work out the widescreen picture's size several times a frame on the game's main thread, and each asked getenv("HOS_WIDE_MAX_PX"): the C runtime's lock and a walk of the whole environment, ~5 % of that thread's samples in a Hyrule Field recording. The status's row bits asked HOS_AUDIO_DEVICE the same way. Both are set before any thread reads the environment (game_host.c hos_switch_set), so they are read once. tests/test_audio_output_devices.py's menu fixture set HOS_AUDIO_DEVICE halfway through its run; it now runs a second time with the variable set before it starts, as a run's switches are. Co-Authored-By: Claude Opus 5.5 <[email protected]>Tested in game: Windows 11 (22631), Ryzen 9 3900X, RTX 3080 (NVIDIA 621.47). These two commits over main
3b3ea2cb3: six runs of play through dev.py ab (Hyrule Field and Market, teleported, ~100 s each) and a profiled Hyrule Field run. Every run played to its end; in the profile the menu's pollers are under 1 % of the main thread's samples (~10 % before). Field +5.5 % fps, Market +5.4 % in the second series (Measurements has every run).Possibly related, for context:
On BeanBot's link: #3208 (moving the Insert menu's logic into the game) deletes
gpu/vk/menu/output.cppandaudio.cpp, and its Rust side readsHOS_WIDE_MAX_PXonce at the run's start (output_start) and keeps the output sizes, asking the screen again only when it changed (follow_screen). So it should remove most of this cost by its own design. If #3208 merges first, this PR shrinks tohost/hos_wide_size.h(or closes, if nothing on the main thread still calls it each frame: I'll profile #3208 then). If this one merges first, #3208 only drops these two files' hunks along with the files.@rebase
I rebased this pull request onto
main(b3bfdc781c): the new head is909990a5c4.Conflicts resolved
game/crates/api/src/services/devices.rs,game/crates/host-sys/src/devices.rsgame/crates/api/src/services/devices.rs,game/crates/api/src/services/devices/tests.rsNothing was built or run: read the resolution before merging.
Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
ac8a6d4dc0909990a5c4Recommendation: Approve. The code is ready: only testing is left. The reported performance gains are from the pre-rebase menu implementation, so they do not establish a gain for this head. The changed monitor-following path also needs the planned Windows and Linux runs. Recommend approval; not approved on the forge.
The change caches the audio-device override and widescreen pixel budget, and keeps screen sizes briefly per thread. It adds cache state and allows screen-size changes to be observed later; the gain after the menu moved to Rust is unmeasured.
Nits (1): optional.
Testing before merging (3) (runs on the systems it can change; it doesn't hold the recommendation)
b3bfdc781cwith interleaved runs in the target and heavy scenes, reporting average and 1% low fps and frame times at player settings. (@fixdoes its part first: Remove the screen-size cache if its remaining calls are too infrequent to justify it.)game/crates/host-sys/src/devices.rs:34: The changed screen-following path has not been exercised on the rebased head on Windows with multiple monitors. (more on the line) Do: On Windows, move the window between differently sized monitors and change a monitor's resolution; verify the output modes and monitor/native marks follow correctly. (@fixdoes its part first: Remove the screen-size cache to eliminate its added delay.)game/crates/host-sys/src/devices.rs:34: The changed platform path has not been exercised on Linux or Steam Deck on this head. (more on the line) Do: Play on Steam Deck and check the Output resolution row and screen-following behavior, as proposed in Still to test. (@fixdoes its part first: Remove the screen-size cache to eliminate its added delay.)@fixcan do L1, L2, L3 and L4.Questions (1) (not confirmed from the code; they don't hold the recommendation)
game/crates/api/src/services/devices/tests.rs:22: Is there a concrete incorrect behavior caused by this test gap that the existing code or repository rules require the test to catch?Checks: Still running:
PR description / Title and description (pull_request_target).More: does it help, other systems, switches, what was read
Does it help: Unproven. The description reports Hyrule Field at 76.65 to 80.85 fps (+5.5%) on the earlier implementation, but those runs are not against this head's base. On this head, screen_sizes is called by follow_screen after monitor listings, normally every 30 frames, rather than by every status query; the old C++ menu paths no longer exist.
Other systems: Screen-size polling can affect monitor moves and resolution changes on Windows and Linux, including Steam Deck. The environment caches affect startup overrides on both platforms. The reported Windows play runs exercised the earlier implementation; no run of this rebased head is reported.
Switches: No switches added or removed. HOS_AUDIO_DEVICE and HOS_WIDE_MAX_PX retain their existing defaults but are now cached after first use; runtime environment changes are no longer observed.
Reviewed:
909990a5c4againstb3bfdc781c: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the pull request template, the full diff and commits, and all four changed files. Traced screen-size callers, monitor following, switch initialization and widescreen callers; skimmed related output-resolution tests. docs/review-checklist.md and the adjacent Tooling checkout were absent. No recorded runs, translations or generated files were changed.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no builds, tests or project scripts were run. CI reports no failures and one description check still running.
Overlaps and merge order: #3208 moved the menu logic to Rust and is already reflected in this rebased head; the author's comment says it removed much of the original target cost.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.
@ -32,3 +32,3 @@/// The monitor the window is on's size, and the main one's: cheap, asked while the game runs./// The monitor the window is on's size, and the main one's, kept for 100 ms per thread.#[must_use]pub fn screen_sizes() -> (Option<ScreenSize>, Option<ScreenSize>) {L2 (should fix): The changed screen-following path has not been exercised on the rebased head on Windows with multiple monitors.
When: When a window moves or a monitor's resolution changes, the cached size can remain in use until a later monitor listing, so the output and aspect-ratio rows may update later.
Do: On Windows, move the window between differently sized monitors and change a monitor's resolution; verify the output modes and monitor/native marks follow correctly.
L3 (should fix): The changed platform path has not been exercised on Linux or Steam Deck on this head.
When: The menu obtains its screen size through the host on Linux too, and the new cache controls when a changed answer reaches the output list.
Do: Play on Steam Deck and check the Output resolution row and screen-following behavior, as proposed in Still to test.
WIP: perf(vk): the menu's status each frame keeps the screen's size and reads HOS_WIDE_MAX_PX and HOS_AUDIO_DEVICE onceto perf(vk): the menu's status each frame keeps the screen's size and reads HOS_WIDE_MAX_PX and HOS_AUDIO_DEVICE once