Merge pull request #745 from rdbtCVS/perf/worker-headroom
🤖 Agent: merged by Ludovic's AI agent. Measured by perf-ticks-6 (comment above): ThinkPad 4 threads RD12 1% low 17→29 FPS (31→40 with --server-thread), FPS up everywhere; in-frame spawn load ~15% slower (32.5→37.2 s); Mac 14 threads within noise. Thanks @rdbtCVS!
This commit is contained in:
@@ -273,9 +273,14 @@ impl Graphics {
|
||||
if self.workers > 0 {
|
||||
return self.workers as usize;
|
||||
}
|
||||
// The pool never takes every core. The render thread and the
|
||||
// integrated server thread (single player runs on its own server
|
||||
// thread by default) each need one, and a pool that fills every core
|
||||
// starves them: the frame rate collapses to single digits while the
|
||||
// workers saturate the CPU and its memory bandwidth.
|
||||
let auto = std::thread::available_parallelism()
|
||||
.map_or(2, |n| n.get())
|
||||
.saturating_sub(1)
|
||||
.saturating_sub(2)
|
||||
.max(1);
|
||||
if self.battery { auto.div_ceil(2) } else { auto }
|
||||
}
|
||||
@@ -359,6 +364,17 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn automatic_workers_leave_cores_for_the_render_and_server_threads() {
|
||||
let g = Graphics::default();
|
||||
assert_eq!(g.workers, 0);
|
||||
let cores = std::thread::available_parallelism().map_or(2, |n| n.get());
|
||||
assert_eq!(g.worker_threads(), cores.saturating_sub(2).max(1));
|
||||
// A manual count is the player's own choice, kept as asked.
|
||||
let manual = Graphics { workers: 3, ..g };
|
||||
assert_eq!(manual.worker_threads(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn battery_mode_only_lowers_the_frame_cap() {
|
||||
let mut g = Graphics::default();
|
||||
|
||||
Reference in New Issue
Block a user