Deduplicate LIVE pipeline tracking and honor VICTORY_LIBRARY_DIR + writer lock in compact() #2577

Manually merged
github merged 1 commit from github-bot/gh-2577 into main 2026-11-30 14:16:16 +00:00 AGit
Owner

@⁠steven-seagull27 on GitHub · 2026-11-29 14:32 UTC · original
steven-seagull27:fix/library-live-dedup-and-compact-dir → main · +259 −18 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC

Summary

Fixes two bugs in crates/victory-gpu/src/pipeline/library.rs:

  1. Deduplicate LIVE pipeline tracking by name (note_live):

    • Previously, LIVE was a Vec<(HSTRING, Later)> and note_live() pushed a cloned HSTRING and ID3D12PipelineState COM reference on every load/create call without deduplication. Repeated loads of the same pipeline name pinned duplicate COM references until exit and inflated live.len() in compact()'s threshold check.
    • Replaced LIVE's backing store with LivePipelines<T> (a BTreeMap<HSTRING, T> plus a duplicate counter) so each unique pipeline name is stored at most once, duplicate calls neither clone the HSTRING nor pin extra COM references, and compact() evaluates compacts() against the true unique-pipeline count while preserving duplicate counts in the rebuild log.
  2. Honor VICTORY_LIBRARY_DIR and acquire writer() lock in compact():

    • Previously, compact() wrote directly to DIR instead of resolving VICTORY_LIBRARY_DIR (unlike save()), and did not acquire the directory's writer() lock (host-pipelines.lock). When VICTORY_LIBRARY_DIR was configured, compaction wrote to the wrong directory, left the shared library untouched, and still set COMPACTED = true, causing save(true) to skip saving newly compiled pipelines. Without the writer() lock, concurrent processes sharing a library directory could race on host-pipelines.tmp and replace_library().
    • Extracted shared resolve_library_dir() / target_library_dir() helpers used by both save() and compact(), and extracted compact_to_dir() which creates the target directory, acquires writer(&shared, Duration::from_secs(30)) (matching save(true)), keeps the lock held across serialization and replace_library(), cleans up host-pipelines.tmp on error, and sets COMPACTED = true only when the locked replacement succeeds. When the lock is contended, compact() logs a warning and returns cleanly without touching disk or marking COMPACTED.

Tests

Added synthetic unit tests in crates/victory-gpu/src/pipeline/library.rs:

  • live_pipelines_deduplicates_by_name_without_pinning_duplicates
  • compact_target_dir_honors_override_and_writes_shared_directory
  • compact_skips_cleanly_when_writer_lock_is_held
  • compact_cleans_up_temp_and_keeps_uncompacted_on_write_error

Verification

  • cargo test --locked -j 2 -p victory-gpu --lib -- pipeline::library --nocapture --test-threads=1 — 17 passed, 0 failed
  • cargo test --locked -j 2 -p victory-gpu --lib -- pipeline:: --test-threads=1 — 74 passed, 0 failed, 2 ignored
  • cargo clippy --locked -j 2 -p victory-gpu --lib --tests — 0 new warnings in crates/victory-gpu/src/pipeline/library.rs
  • git diff --check — clean
**@⁠steven-seagull27** on GitHub · 2026-11-29 14:32 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2577) `steven-seagull27:fix/library-live-dedup-and-compact-dir` → `main` · +259 −18 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC ## Summary Fixes two bugs in `crates/victory-gpu/src/pipeline/library.rs`: 1. **Deduplicate `LIVE` pipeline tracking by name (`note_live`):** - Previously, `LIVE` was a `Vec<(HSTRING, Later)>` and `note_live()` pushed a cloned `HSTRING` and `ID3D12PipelineState` COM reference on every load/create call without deduplication. Repeated loads of the same pipeline name pinned duplicate COM references until exit and inflated `live.len()` in `compact()`'s threshold check. - Replaced `LIVE`'s backing store with `LivePipelines<T>` (a `BTreeMap<HSTRING, T>` plus a duplicate counter) so each unique pipeline name is stored at most once, duplicate calls neither clone the `HSTRING` nor pin extra COM references, and `compact()` evaluates `compacts()` against the true unique-pipeline count while preserving duplicate counts in the rebuild log. 2. **Honor `VICTORY_LIBRARY_DIR` and acquire `writer()` lock in `compact()`:** - Previously, `compact()` wrote directly to `DIR` instead of resolving `VICTORY_LIBRARY_DIR` (unlike `save()`), and did not acquire the directory's `writer()` lock (`host-pipelines.lock`). When `VICTORY_LIBRARY_DIR` was configured, compaction wrote to the wrong directory, left the shared library untouched, and still set `COMPACTED = true`, causing `save(true)` to skip saving newly compiled pipelines. Without the `writer()` lock, concurrent processes sharing a library directory could race on `host-pipelines.tmp` and `replace_library()`. - Extracted shared `resolve_library_dir()` / `target_library_dir()` helpers used by both `save()` and `compact()`, and extracted `compact_to_dir()` which creates the target directory, acquires `writer(&shared, Duration::from_secs(30))` (matching `save(true)`), keeps the lock held across serialization and `replace_library()`, cleans up `host-pipelines.tmp` on error, and sets `COMPACTED = true` only when the locked replacement succeeds. When the lock is contended, `compact()` logs a warning and returns cleanly without touching disk or marking `COMPACTED`. ## Tests Added synthetic unit tests in `crates/victory-gpu/src/pipeline/library.rs`: - `live_pipelines_deduplicates_by_name_without_pinning_duplicates` - `compact_target_dir_honors_override_and_writes_shared_directory` - `compact_skips_cleanly_when_writer_lock_is_held` - `compact_cleans_up_temp_and_keeps_uncompacted_on_write_error` ### Verification - `cargo test --locked -j 2 -p victory-gpu --lib -- pipeline::library --nocapture --test-threads=1` — 17 passed, 0 failed - `cargo test --locked -j 2 -p victory-gpu --lib -- pipeline:: --test-threads=1` — 74 passed, 0 failed, 2 ignored - `cargo clippy --locked -j 2 -p victory-gpu --lib --tests` — 0 new warnings in `crates/victory-gpu/src/pipeline/library.rs` - `git diff --check` — clean
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 14:33:52 +00:00
github manually merged commit 1c9331584d into main 2026-11-30 14:16:16 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!2577
No description provided.