Repository navigation
perf(gpu): list threads' lookups without shared locks (VICTORY_PLACED_SEEN, VICTORY_VIEWS_SHARDED, VICTORY_SHADOW_SHARDED) - #331
Conversation
…s remembered by thread, views' and host copies' tables read under per-thread lock shards (VICTORY_PLACED_SEEN, VICTORY_VIEWS_SHARDED, VICTORY_SHADOW_SHARDED)
|
Read-only security & triage review on
|
|
Automated triage for the maintainers (not an approval). Verdict: Review SummaryThe overall idea—eliminating shared cache-line bouncing on However, there is a concrete deadlock bug in Blocking Issue
Non-blocking Notes
To change the verdict:
Generated with Antigravity CLI ( |
|
Allowlist & Architect Deep Review ( Status:
Once fixed and CI is green, this will need a plain |
Summary
The threads that translate list calls (
VICTORY_THIN) spend much of their time in short lookups that return the same answer draw after draw, behind locks every one of them takes. Even uncontended, taking a sharedRwLockfor reading writes its cache line, which then moves between cores on every read. Three cuts, each with its own switch (on unless0; diagnostics builds can switch each inside a run withVICTORY_AB):VICTORY_PLACED_SEEN:resource::texture_at(aMutexover aBTreeMapof 64-byte keys, taken for every view of placed memory a draw reads) is answered from a small per-thread table first. Safe becausePLACED_TEXTURESis append-only (a texture made for a place and description is kept for the run); a comment on the table now says so.VICTORY_VIEWS_SHARDED: the table of every view (descriptor::VIEWS) is read under one of 16 cache-line-padded locks chosen by the reading thread; a writer takes all of them in order. Same exclusion as oneRwLock; a thread that reads again while reading reuses its first lock (no writer can wedge between).views_read/views_writekeep their try-first-then-count-the-wait shape (ReadMostly::try_writeadded for that).VICTORY_SHADOW_SHARDED: the same for the host copies' tablesshadow::BUFFERSandshadow::LOOSE.The three are in our fork's play defaults since 1 Dec.
Changes
crates/victory-gpu/src/listcpu.rs(new): the switches,ReadMostly<T>(+try_read/try_write),Remembered<K, V, N>,hash_words; tests (concurrent readers under both lock modes while the switch flips, never seeing a half write; try-lock behaviour; memo correctness).crates/victory-gpu/src/resource.rs:texture_at->texture_at_seen/texture_at_table; testa_remembered_placed_texture_is_the_tables(skips without a host device, as the neighbouring test does).crates/victory-gpu/src/descriptor.rs:VIEWSasOnceLock<ReadMostly<Views>>;views_read/views_write.crates/victory-gpu/src/shadow.rs:BUFFERS,LOOSEasReadMostly;.read()/.write()call sites withoutunwrap_or_else(poisoning handled inside).crates/victory-gpu/src/lib.rs:mod listcpu;.host.rsuntouched.Rig Specs Tested On (our fork, not this tree)
Run Settings & Profile
VICTORY_AB(7-8 switches, 10 s phases in a mixed order, 56 phases at the busiest place of a saved game), drift fitted; list threads' processor time per phase from the per-thread CPU countersMeasurements & Verification
PLACED_SEENVIEWS_SHARDEDSHADOW_SHARDEDSHADOW_SHARDEDslowest 1 % +3 +- 4 ms, not resolved). Pictures compared at fixed points: the same.thin_ms(list calls translated by threads of ours per frame) line.main3230974; offline,--locked, toolchain 1.98.1-msvc):cargo clippy --workspace --all-targets --locked -- -D warningscargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo test(not run by us on this tree)cargo xtask policy(not run; files stay far below the 640 KiB limit)Limits
PLACED_SEENrelies onPLACED_TEXTURESnever losing an entry: anyone who later evicts entries from that table must turn this off or bump a generation the memo checks.shadow.rs: it merged without a conflict and passes clippy, but our measurements predate victory-gpu: budget-reactive card pools, 4 MiB shared heaps, and CPU-only shadow staging #322.