perf(victory-gpu): use RwLock for early pipeline tracking and avoid Call string formatting #416

Merged
Lewandox merged 2 commits from upstream-pr/416 into main 2026-11-26 18:52:20 +00:00
Lewandox commented 2026-11-26 18:00:05 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Lewandox on 2026-11-26T18:00:05Z.


Summary

Removes unnecessary heap allocations and mutex contention on the hot pipeline-library lookup/creation path while keeping identical removal_note() diagnostics on device removal.

Changes

  1. USED (wanted_early / note_used) — RwLock + zero-allocation check:

    • Switched USED from Mutex<Option<HashSet<String>>> to RwLock<Option<HashSet<String>>> with lazy initialization helper ensure_used().
    • wanted_early(key) now takes a shared read lock instead of an exclusive mutex.
    • note_used(key) checks membership and the EARLY_MAX cap under a shared read lock first, returning immediately with zero write lock and zero key.to_owned() heap allocation once a pipeline key has been seen.
  2. Call / CALLS — deferred string formatting & inline pipeline names:

    • Stored thread-local LABEL as Arc<str> instead of cloning a heap String on every call().
    • Introduced compact CallName (Inline([u8; 32], u8) / Heap(String)) so 32-byte pipeline hash keys do not allocate on the heap during call("load" | "make" | "store", name).
    • Deferred format!("{name} {label}") so formatting only happens inside removal_note() if a device removal actually occurs.
  3. Tests:

    • Added unit tests for CallName inline/heap storage, Call formatting in removal_note(), and wanted_early / note_used behavior.

Verification

  • cargo test -p victory-gpu --lib pipeline::library::tests (default and --features diagnostics)
  • cargo xtask policy
<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5514928156 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/416). Originally posted by [Lewandox](https://github.com/Lewandox) on 2026-11-26T18:00:05Z. --- ## Summary Removes unnecessary heap allocations and mutex contention on the hot pipeline-library lookup/creation path while keeping identical `removal_note()` diagnostics on device removal. ### Changes 1. **`USED` (`wanted_early` / `note_used`) — `RwLock` + zero-allocation check**: - Switched `USED` from `Mutex<Option<HashSet<String>>>` to `RwLock<Option<HashSet<String>>>` with lazy initialization helper `ensure_used()`. - `wanted_early(key)` now takes a shared read lock instead of an exclusive mutex. - `note_used(key)` checks membership and the `EARLY_MAX` cap under a shared read lock first, returning immediately with zero write lock and zero `key.to_owned()` heap allocation once a pipeline key has been seen. 2. **`Call` / `CALLS` — deferred string formatting & inline pipeline names**: - Stored thread-local `LABEL` as `Arc<str>` instead of cloning a heap `String` on every `call()`. - Introduced compact `CallName` (`Inline([u8; 32], u8)` / `Heap(String)`) so 32-byte pipeline hash keys do not allocate on the heap during `call("load" | "make" | "store", name)`. - Deferred `format!("{name} {label}")` so formatting only happens inside `removal_note()` if a device removal actually occurs. 3. **Tests**: - Added unit tests for `CallName` inline/heap storage, `Call` formatting in `removal_note()`, and `wanted_early` / `note_used` behavior. ## Verification - `cargo test -p victory-gpu --lib pipeline::library::tests` (default and `--features diagnostics`) - `cargo xtask policy`
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LooperSalty/AnyXboxX!416
No description provided.