From 002cf4aa97ff648cf39bd82cafbaef8bd584d63d Mon Sep 17 00:00:00 2001 From: readmet3xt-lab <238408149+readmet3xt-lab@users.noreply.github.com> Date: Thu, 26 Nov 2026 16:51:16 +0530 Subject: [PATCH] VICTORY_HELPER_PRIORITY: a priority for the threads a frame waits for A frame timeline of the first gameplay area had our listing, records and landing threads woken and not running yet for 4-11 ms of the chain the present came out of. The switch sets the priority of every thread that asks for the fast cores. Not on by default: four bench runs (helper builds running beside them) were within the noise. Co-Authored-By: Claude Opus 5.5 --- crates/victory-gpu/src/cores.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/victory-gpu/src/cores.rs b/crates/victory-gpu/src/cores.rs index 4d51fc8..0e1ad30 100644 --- a/crates/victory-gpu/src/cores.rs +++ b/crates/victory-gpu/src/cores.rs @@ -69,8 +69,27 @@ pub(crate) fn keep_many_on_fast_cores(what: &str) { ask(what, 3); } +/// The priority our own threads that a frame waits for, and those they share +/// their work with, run at (`VICTORY_HELPER_PRIORITY=`, a thread priority +/// from -2 to 2; not given: as made, normal, the submitting thread above +/// normal). A frame's timeline in the first gameplay area (run timeline, +/// 2026-11-26) had such threads woken and not running yet for 4-11 ms of its +/// chain: the listing threads up to 5.4 ms at a time, while the title's own +/// workers held every processor. +fn helper_priority() -> Option { + static PRIORITY: std::sync::OnceLock> = std::sync::OnceLock::new(); + *PRIORITY.get_or_init(|| { + std::env::var("VICTORY_HELPER_PRIORITY").ok().and_then(|v| v.trim().parse::().ok()).map(|p| p.clamp(-2, 2)) + }) +} + fn ask(what: &str, from: u32) { - use windows_sys::Win32::System::Threading::{GetCurrentThread, SetThreadSelectedCpuSets}; + use windows_sys::Win32::System::Threading::{GetCurrentThread, SetThreadPriority, SetThreadSelectedCpuSets}; + if let Some(priority) = helper_priority() { + // SAFETY: this thread's own priority. + let set = unsafe { SetThreadPriority(GetCurrentThread(), priority) } != 0; + tracing::debug!(what, priority, set, "the thread's priority (VICTORY_HELPER_PRIORITY)"); + } if stage() < from { return; }