perf(resource): gate filler-twins statistics behind diagnostics

texture_at's filler-twins tracking (PLACED_RAW, PLACED_TWINS, and the
per-call block in texture_at that takes PLACED_RAW's own mutex and scans
previously-seen raw descriptions at the same address) exists solely to
feed placed_filler_twins(), whose only caller is copystat::log_memory --
itself compiled only with feature = "diagnostics". A build without that
feature paid for the second mutex, the BTreeSet, and an O(seen-so-far)
scan on every placed-texture lookup (hit or miss) with no consumer for
the result.

Gates PLACED_RAW, PLACED_TWINS, placed_filler_twins(), the `raw` binding,
and the tracking block itself behind feature = "diagnostics". The
functional cache (PLACED_TEXTURES) and its key (`key`, built from
VICTORY_PLACED_FILLER the same way as before) are untouched -- this
candidate never reads or writes PLACED_TEXTURES.

Independently reviewed before implementing (see
research/reviews/OPTIMIZATION_CANDIDATE_B_REVIEW.md): re-ran the
existing experiments/optimization-validation/filler.rs equivalence
tests myself (6/6 pass, both configs), confirmed the eliminated block
has no path into the functional cache, confirmed no equivalent change
exists upstream (checked ZJOU 477c395a directly -- it gates only the
getter, not the producer -- and did a fresh PR search).

Verified after implementing: cargo test --workspace --locked (27 result
lines) and cargo test -p victory-gpu --features diagnostics --lib (381
tests) are byte-for-byte identical in pass/fail/ignored counts between
this branch and an unpatched origin/main worktree. cargo clippy, both
CI invocations (with and without --all-features), produce an identical
error set to the same unpatched worktree (a pre-existing, unrelated
victory-formats issue blocks the workspace-wide command in both).

Does not implement candidate A (incremental VIEWS census) or the shapes
segmentation candidate, per instruction. No game files used, no push,
no PR.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
Local TestandClaude Sonnet 5 committed 2026-11-27 01:18:17 +01:00
1 parent 6a31e431e7
commit 5b36758982
1 file changed
+19 -6
+19 -6
View File
@@ -2932,19 +2932,25 @@ static PLACED_TEXTURES: std::sync::Mutex<std::collections::BTreeMap<(u64, [u32;
std::sync::Mutex::new(std::collections::BTreeMap::new());
/// The placed textures asked for with filler words set, as asked
/// (address and description): for [`PLACED_TWINS`].
#[cfg(windows)]
/// (address and description): for [`PLACED_TWINS`]. Diagnostics builds
/// only: nothing outside `copystat` (itself diagnostics-only) consumes
/// [`placed_filler_twins`], so a build without that feature carries
/// neither this set nor its own mutex, nor the per-call tracking in
/// [`texture_at`] that would otherwise take it on every placed-texture
/// lookup, hit or not.
#[cfg(all(windows, feature = "diagnostics"))]
static PLACED_RAW: std::sync::Mutex<std::collections::BTreeSet<(u64, [u32; 14])>> =
std::sync::Mutex::new(std::collections::BTreeSet::new());
/// Placed textures asked for a second time with other filler words in
/// their description: each was a second resource and host copy before the
/// filler was left out of the key ([`texture_at`]).
#[cfg(windows)]
/// filler was left out of the key ([`texture_at`]). Diagnostics builds
/// only; see [`PLACED_RAW`].
#[cfg(all(windows, feature = "diagnostics"))]
static PLACED_TWINS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
/// See [`PLACED_TWINS`].
#[cfg(windows)]
#[cfg(all(windows, feature = "diagnostics"))]
pub(crate) fn placed_filler_twins() -> u64 {
PLACED_TWINS.load(std::sync::atomic::Ordering::Relaxed)
}
@@ -3025,6 +3031,9 @@ pub(crate) fn texture_at(address: u64, desc: &[u32; 14]) -> Option<This> {
// that fills at world entry. They are not part of what a texture is.
// `VICTORY_PLACED_FILLER=1`: kept in the key, as before.
static KEPT: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
// Only the diagnostics-only filler-twins tracking below reads `raw`;
// the functional cache key is `key` alone.
#[cfg(feature = "diagnostics")]
let raw = *desc;
let mut key = *desc;
if !*KEPT.get_or_init(|| std::env::var_os("VICTORY_PLACED_FILLER").is_some_and(|v| v == "1")) {
@@ -3034,7 +3043,11 @@ pub(crate) fn texture_at(address: u64, desc: &[u32; 14]) -> Option<This> {
let desc = &key;
let mut map = PLACED_TEXTURES.lock().unwrap_or_else(|e| e.into_inner());
// How many resources the filler alone would have added (a count for
// the log: `placed_filler_twins`).
// the log: `placed_filler_twins`). Diagnostics builds only: without
// that feature this whole block -- its mutex, its set, and its O(seen
// so far at this address) scan on every new raw description -- does
// not exist, not just "does nothing"; see `PLACED_RAW`.
#[cfg(feature = "diagnostics")]
if raw != key {
let mut seen = PLACED_RAW.lock().unwrap_or_else(|e| e.into_inner());
if seen.insert((address, raw)) {