warm: leave two CPU threads per default worker

This commit is contained in:
loyodea
2026-12-03 19:07:35 +02:00
parent 276f22c501
commit cbeb035d9a
6 changed files with 55 additions and 12 deletions

View File

@ -128,7 +128,8 @@ enum Command {
/// of the translator or the driver. Goes on where it was stopped.
#[cfg(windows)]
Warm {
/// Processes at once (default: two thirds of the logical cores).
/// Processes at once (default: VICTORY_WARM_JOBS, otherwise half
/// the logical cores, at most 16 and limited by memory).
#[arg(long)]
jobs: Option<usize>,
/// At most this many pipelines.

View File

@ -107,8 +107,7 @@ pub fn run(
.collect();
all.sort_by_key(|&n| (!early.contains(keys[n].as_str()), &keys[n]));
all.truncate(limit.unwrap_or(usize::MAX));
let cores = std::thread::available_parallelism().map_or(4, |n| n.get());
let jobs = jobs.unwrap_or(cores * 2 / 3).max(1);
let jobs = jobs.unwrap_or_else(known::preparation_jobs).max(1);
println!(
"{} pipelines known, {} made before ({fingerprint}), {} bad, {} refused by the host; {} to make, {jobs} processes",
keys.len(),

View File

@ -573,6 +573,11 @@ pub fn repair_shaders(dir: &Path) -> std::io::Result<()> {
})
}
/// Worker count shared by standalone and pre-game pipeline preparation.
pub fn preparation_jobs() -> usize {
super::prepared::jobs()
}
pub fn prepare_start() -> std::io::Result<()> {
super::prepared::warm()?;
Ok(())

View File

@ -324,11 +324,10 @@ pub(super) fn pipeline(
Ok(pso)
}
/// Processes that make the pipelines before the game: two thirds of the
/// logical processors, as `victory warm` takes by itself, at most 16 and as
/// many as the memory takes (768 MiB each beside 8 GiB). Half of them, at
/// most 10, left a 24-thread i7-13700K 38% idle for the half hour a new
/// translator takes (2026-12-02: 7,000 of 94,839 in 170 s, workers at 100%).
/// Processes that make the pipelines before the game: half the logical
/// processors, at most 16 and as many as the memory takes (768 MiB each
/// beside 8 GiB). A worker can use two CPU threads: on the 24-core,
/// non-SMT host in #325, 12 processes made progress while 16 stalled.
pub(super) fn jobs() -> usize {
// VICTORY_WARM_JOBS=<n>: that many, 1 to 64, whatever the memory says.
if let Some(n) = std::env::var("VICTORY_WARM_JOBS")
@ -340,7 +339,11 @@ pub(super) fn jobs() -> usize {
let cpus = std::thread::available_parallelism().map_or(2, |n| n.get());
let memory = crate::host::available_physical_ram()
.map_or(4, |n| (n.saturating_sub(8 << 30) / (768 << 20)) as usize);
memory.min(cpus * 2 / 3).clamp(1, 16)
default_jobs(cpus, memory)
}
fn default_jobs(cpus: usize, memory: usize) -> usize {
memory.min(cpus / 2).clamp(1, 16)
}
pub(super) fn warm() -> io::Result<()> {
@ -356,3 +359,31 @@ pub(super) fn warm() -> io::Result<()> {
)))
}
}
#[cfg(test)]
mod tests {
use super::default_jobs;
#[test]
fn reported_24_core_host_leaves_room_for_two_threads_per_worker() {
assert_eq!(default_jobs(24, 32), 12);
}
#[test]
fn small_hosts_keep_at_least_one_worker() {
assert_eq!(default_jobs(1, 8), 1);
assert_eq!(default_jobs(2, 8), 1);
assert_eq!(default_jobs(3, 8), 1);
}
#[test]
fn memory_still_limits_workers() {
assert_eq!(default_jobs(24, 4), 4);
assert_eq!(default_jobs(24, 0), 1);
}
#[test]
fn large_hosts_keep_the_process_cap() {
assert_eq!(default_jobs(64, 64), 16);
}
}

View File

@ -100,9 +100,15 @@ kept.
| `VICTORY_SKIP_BINK` | unset | 1, all | `1`: skips one-time movies. `all`: also skips looping menu backgrounds, which stay dark |
| `VICTORY_SKIP_INTRO` | unset | 0, 1 | Skips only the intro movie |
| `VICTORY_WARM` | unset | 0, 1 | `0`: no pipeline preparation before start |
| `VICTORY_WARM_JOBS` | unset | 1 to 64 | Pipeline preparation processes. Unset: two thirds of logical processors, at most 16, limited by memory |
| `VICTORY_WARM_JOBS` | unset | 1 to 64 | Pipeline preparation processes. Unset: half the logical processors, at least 1 and at most 16, limited by memory |
| `VICTORY_WARM_SYNC` | unset | 0, 1 | `1`: syncs each prepared pipeline file to disk (slower) |
A preparation worker can use two CPU threads. Too many processes can stall
preparation on some systems; if workers stop making progress, lower
`VICTORY_WARM_JOBS` (for example, to 10). An explicit value overrides the CPU
and memory limits of the default. For standalone `victory warm`, `--jobs`
takes precedence over `VICTORY_WARM_JOBS`.
### Textures and glass
| Setting | Default | Values | Effect |

View File

@ -227,8 +227,9 @@ VICTORY_SKIP_INTRO=
# 0: open the game without preparing pipelines first (made at first use).
VICTORY_WARM=
# Processes that prepare the pipelines, 1 to 64. Unset: two thirds of the
# logical processors, at most 16, as many as the memory takes.
# Processes that prepare the pipelines, 1 to 64. Unset: half the logical
# processors, at most 16, as many as the memory takes. Too many can stall
# preparation on some systems: lower this if workers stop making progress.
VICTORY_WARM_JOBS=
# 1: sync each prepared pipeline's file to the disk as it is written (slower;