From 3269180b4be01376ab772add35cdf5f1b60599a7 Mon Sep 17 00:00:00 2001 From: vilanxVI <362155133+vilanx@users.noreply.github.com> Date: Fri, 27 Nov 2026 21:28:43 -0300 Subject: [PATCH] copystat: register the counting allocator only in diagnostics builds The #[global_allocator] registration carried no cfg, although its own doc comment says the counters are for diagnostics builds only. A plain release build therefore paid a thread-local lookup and an atomic add on every allocation and every release in the process, the title's own included. The counters are not at fault: they are banked 32 ways and the bank is #[repr(align(64))], so this was never false sharing, just the per-call cost. Measured on an RTX 3060 and an i7-9700 (8 cores, no SMT), Series S, DLSS performance, samples paired by draw count: 13.6% to 19.4% off the frame time across four draw bins, against 7.6% run-to-run noise. The submitting thread, the critical path there, went from 72.5 ms to 56.4 ms. Co-Authored-By: Claude Opus 5 --- crates/victory-gpu/src/copystat.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/victory-gpu/src/copystat.rs b/crates/victory-gpu/src/copystat.rs index 3bbb9dd6a..50022b57c 100644 --- a/crates/victory-gpu/src/copystat.rs +++ b/crates/victory-gpu/src/copystat.rs @@ -381,6 +381,7 @@ fn big_blocks() -> String { /// The system's allocator with every block counted in [`OWN`] (two atomic /// additions per allocation and per release: diagnostics builds only). +#[allow(dead_code)] struct Counting; // SAFETY: every call goes to the system's allocator unchanged; only @@ -426,6 +427,9 @@ unsafe impl std::alloc::GlobalAlloc for Counting { } } +// Only in diagnostics builds, as the doc above states: every allocation and +// release in the process otherwise pays for the counters. +#[cfg(feature = "diagnostics")] #[global_allocator] static HEAP: Counting = Counting;