perf(host): the game's nn::os::YieldThread gives up its virtual core only, not the processor (HOS_OS_YIELD=1 as before) #1663
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
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
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1663
Loading…
Reference in a new issue
No description provided.
Delete branch "GummiNaomi/Longshot:perf/os-yield-vcore-only"
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?
Type: perf · Risk: medium · Tested on: Windows 11, RTX 4070 SUPER, Ryzen 9 9950X3D (SMT off) · Needs: a build of this head; a Steam Deck or another CPU of 4 cores; Linux; Intel and AMD CPUs with SMT
Stacked on #1661 (the in-run A/B tool): its first commit is that PR's; this PR is the second commit.
TL;DR
The game gives way to other threads after every small job, thousands of times a frame. Longshot did that twice: it handed over the game's own core, then asked Windows to switch threads too, which costs kernel time on every call. This PR keeps only the first hand-over, which is what the game asks for. Standing in Castle Town's market with the game on 4 cores, frames were 2.1 % and 1.7 % shorter (two in-run A/Bs, both intervals clear of zero); on 16 cores no difference.
Breakdown
SwitchToThread, and on 4 cores the job threads spent about as long inside it as running.nn::os::YieldThreadgives up the game's virtual core only;HOS_OS_YIELD=1brings the processor's yield back.HOS_AB) on 4 and 16 cores in the market, two runs each, on a tree 93 commits behind this main; a test that reads the wiring.Why
OoT's job system yields (
nn::os::YieldThread) after every job and every actor callback. Longshot answered each yield in two steps:hos_vcore_yield(), which hands the game's virtual core to a waiting game thread of equal or better priority (what the console's yield does), then Windows'SwitchToThread(). On a PC of 4 cores standing in Castle Town's market, a Windows profile counted the six BaseProc executor threads at 107 % of a core: 45.5 % running and 51.6 % insideSwitchToThread, handing the processor to another thread and taking it back. Over all the job threads that was about three quarters of one of the four processors, spent in the kernel. With few cores every processor is busy, so that time comes out of the frame.What changed
The game's yield keeps its virtual core hand-over and drops the processor's: a game thread that was waiting for the core still gets it, and Windows still moves threads between processors at the end of their time slices.
host/hos_thread.cos_yield()andHLE(_ZN2nn2os11YieldThreadEv):SwitchToThread()only withHOS_OS_YIELD=1. The switch is read throughhos_ab_value, soHOS_ABmay flip it between two yields (nothing is kept between yields).HOS_OS_YIELD=1row indocs/development.mdbeside the virtual-core rows; the row ingpu/vk/switches.def.tests/test_hos_ab.py's list of wired switches gainsHOS_OS_YIELD.Measurements
Verdict: faster on 4 cores: frame time -2.1 % and -1.7 % (95 % intervals -3.0 to -1.3 % and -2.9 to -0.5 %), frames of 16.7 ms or more down 5 points; on 16 cores no difference (intervals around 0).
Hardware: Windows 11, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB
Scene: Castle Town's market (child), standing after a debug teleport from the
kokiri-startsave; output 2560x1440, uncapped (HOS_FPS_MAX=1000), no window (HOS_HEADLESS=1). "4 cores": the game kept to cores 8-11 (affinity 0xF00,HOS_CACHE_CORES=0); "16 cores": no affinity, the game on the 8 cores of the 96 MB L3 by defaultMethod: in-run A/Bs (
HOS_AB=<switch>,3,130: 3 s periods after 130 s), about 160 s standing,RX_VK_FRAME_TRACE=1;scripts/ab_summary.pyon each trace (transitions left out, a bootstrap of whole periods for the interval); two runs eachHow to reproduce: 4 cores
HOS_AB=HOS_OS_YIELD=1,3,130on this PR (side 1 is the old way); the runs also hadRX_VK_ASTC_BC_ALL=1 RX_VK_IMAGE_BLOCK_MB=32 RX_VK_LOAD=create RX_VK_BC_LAYERS=8 RX_VK_LATE_FIX=0 HOS_THREAD_TIMES=5Baseline: both sides of each run come from one build, main @
54a42715(93 commits before this PR's base) with the 18 Nov changes, before they were rebased onto main @10de79fbas separate PRs; the switch flipped every 3 s within the run. On 4 cores that build's default was the old yield and side 1 this PR's; on 16 cores (a later build of the same tree) the default was this PR's and side 1 the old.SwitchToThread): build @54a4271554a42715(The 4-core runs' A/B value was
HOS_OS_YIELD=0because that build's switch had the old way as its default; the 16-core runs' was=1. Side 1 is the A/B's value in each.)Flags and settings
One switch added; the new behaviour is the default.
HOS_OS_YIELD=1bringsSwitchToThreadbackTesting
Tested: in the game, at 93 commits behind this base: the A/Bs above, on 4 and 16 cores, every run to its end with 0 errors and the market drawn in its screenshots. On this head:
python -I -B tests/test_hos_ab.py --cc clangpasses; the checks that read the changed files failed only where they fail on main on this PC (run on this branch before its rebase onto main's last 11 commits, which merged without a conflict; after it,tests/test_hos_ab.pypasses again).Not tested: a build of this exact head; Linux (
SwitchToThreadissched_yieldthere); CPUs with SMT (two threads a core); a Steam Deck.Must be tested:
HOS_AB=HOS_OS_YIELD=1,3,60 RX_VK_FRAME_TRACE=1for three minutes, expecting the log'sab: HOS_OS_YIELD=1line andscripts/ab_summary.pyto show side 1 (the old way) no faster (by hand: me)Risks
What could break: a game thread that yields in a loop waiting for another thread to run on the same processor now waits until its time slice ends instead of handing the processor over at once. The virtual cores already hand the game's core over, and none of the runs above stalled, but on a CPU with fewer processors than the game's busy threads (2 cores) this is untested.
Turning it off:
HOS_OS_YIELD=1.Compatibility: nothing changes for saves, options or caches.
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). (The changed files' checks on this PC; failures are main's own here.)third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.tests/that reads changed source updated in this PR, not weakened.🤖 Generated with Claude Code
mooki referenced this pull request2026-11-18 23:27:04 +00:00
mooki referenced this pull request2026-11-19 01:40:29 +00:00
mooki referenced this pull request2026-11-19 02:00:05 +00:00