perf(gpu,pipeline): speed up pipeline compilation, caching, and startup queuing #552

Open
github-bot wants to merge 2 commits from github-bot/gh-552 into main AGit
Owner

@⁠professional-pussy-eater on GitHub · 2026-12-06 02:25 UTC · original
professional-pussy-eater:pipeline-compilation-improvements → main · +1762 −460 · 7 files · 2 commits · open

Optimize cold and warm D3D12 pipeline compilation while keeping existing on-disk shader caches, scoped PSO blob caches, and pipeline catalog files byte-for-byte compatible.

Changes:

  • Root signature & geometry shader caching + zero-alloc warmup skip (pipeline/host.rs):

    • Cache (ID3D12RootSignature, Arc<[u8]>) by exact root layout and device using a thread-local scratch key, avoiding repeated D3D12SerializeVersionedRootSignature and CreateRootSignature calls.
    • Cache GraphicsState::describe() in a OnceLock<String> and format directly into a pre-sized buffer.
    • Eliminate per-pipeline code_bytes() DXIL copies and " quad mask" allocations by hashing &[u8] slices directly into stack [u8; 32] hex names (blobs::name_hex_with_suffix).
    • Check blobs::skip_if_warming_on_disk before constructing Plan, Vec<Stage>, D3D12_GRAPHICS_PIPELINE_STATE_DESC, or label strings.
    • Cache synthesized rect_list_gs DXIL by (vs_hash, ps_hash, quad) and gate HostPipeline.state formatting behind feature = "diagnostics".
  • Sharded blob directory index & multi-threaded writers (pipeline/blobs.rs):

    • Add a lazy 256-bucket directory index (Shards) backed by read_dir scans to replace ~100k+ per-file metadata() / ENOENT syscalls, and track created shard subdirectories to avoid repeated create_dir_all.
    • Compute blob header BLAKE3 checksums on compiling worker threads while blobs are hot in CPU cache instead of serializing hashing on one writer.
    • Replace the single blob writer thread with a 2-4 thread writer pool writing [header, blob] in a single write_all via reusable scratch buffers, updating the shard index before removing entries from pending.
    • Add flush_queue so LARP_PRELOAD=1 exits promptly once blobs flush.
  • Parallel catalog loading & smart queue scheduling (pipeline/make.rs, pipeline/created.rs):

    • Read catalog files concurrently, hash created-shaders.bin containers in parallel, store each listed record's stream subobjects in one flat buffer instead of per-subobject Vec<u8> allocations, build Pending entries in parallel waves, interleave graphics by primary shader hash, and batch SHARED / QUEUE insertions.
    • Cap concurrent heavy compute compiles (>= 96 KiB, largest-first) and total compute workers while graphics pipelines are queued so graphics stream in parallel without thrashing memory/L3/driver compiler, while keeping idle workers busy draining remaining compute once graphics finish.
    • Track active shader translation (Shader::translating) and scan a bounded 32-entry window in Queue::pop to avoid worker OnceLock convoys.
  • Single-pass GFX10 store analysis & cache helpers (pipeline.rs, larp-pipeline/src/cache.rs):

    • Merge stores, stores_by_address, and stores_images into a single store_flags() pass that decodes GFX10 bytecode once instead of 3x.
    • Cache shard directory creation in larp_pipeline::Cache and add CacheKey::from_slices, Cache::read, and Cache::put.

Testing:

  • Added unit tests for GraphicsState::describe() equivalence/caching, name_with_suffix hash equivalence, sharded blob persistence/reopen, bounded heavy-compute scheduling, anti-convoy skipping, shader interleaving, and CacheKey::from_slices.
  • Verified cargo test -p larp-pipeline -p larp-gpu, cargo check -p larp-gpu --features diagnostics, and cargo build --release -p larp.
**@⁠professional-pussy-eater** on GitHub · 2026-12-06 02:25 UTC · [original](https://github.com/gamingwithhomie/larp/pull/552) `professional-pussy-eater:pipeline-compilation-improvements` → `main` · +1762 −460 · 7 files · 2 commits · open Optimize cold and warm D3D12 pipeline compilation while keeping existing on-disk shader caches, scoped PSO blob caches, and pipeline catalog files byte-for-byte compatible. Changes: - Root signature & geometry shader caching + zero-alloc warmup skip (`pipeline/host.rs`): - Cache `(ID3D12RootSignature, Arc<[u8]>)` by exact root layout and device using a thread-local scratch key, avoiding repeated `D3D12SerializeVersionedRootSignature` and `CreateRootSignature` calls. - Cache `GraphicsState::describe()` in a `OnceLock<String>` and format directly into a pre-sized buffer. - Eliminate per-pipeline `code_bytes()` DXIL copies and `" quad mask"` allocations by hashing `&[u8]` slices directly into stack `[u8; 32]` hex names (`blobs::name_hex_with_suffix`). - Check `blobs::skip_if_warming_on_disk` before constructing `Plan`, `Vec<Stage>`, `D3D12_GRAPHICS_PIPELINE_STATE_DESC`, or label strings. - Cache synthesized `rect_list_gs` DXIL by `(vs_hash, ps_hash, quad)` and gate `HostPipeline.state` formatting behind `feature = "diagnostics"`. - Sharded blob directory index & multi-threaded writers (`pipeline/blobs.rs`): - Add a lazy 256-bucket directory index (`Shards`) backed by `read_dir` scans to replace ~100k+ per-file `metadata()` / `ENOENT` syscalls, and track created shard subdirectories to avoid repeated `create_dir_all`. - Compute blob header BLAKE3 checksums on compiling worker threads while blobs are hot in CPU cache instead of serializing hashing on one writer. - Replace the single blob writer thread with a 2-4 thread writer pool writing `[header, blob]` in a single `write_all` via reusable scratch buffers, updating the shard index before removing entries from `pending`. - Add `flush_queue` so `LARP_PRELOAD=1` exits promptly once blobs flush. - Parallel catalog loading & smart queue scheduling (`pipeline/make.rs`, `pipeline/created.rs`): - Read catalog files concurrently, hash `created-shaders.bin` containers in parallel, store each listed record's stream subobjects in one flat buffer instead of per-subobject `Vec<u8>` allocations, build `Pending` entries in parallel waves, interleave graphics by primary shader hash, and batch `SHARED` / `QUEUE` insertions. - Cap concurrent heavy compute compiles (`>= 96 KiB`, largest-first) and total compute workers while graphics pipelines are queued so graphics stream in parallel without thrashing memory/L3/driver compiler, while keeping idle workers busy draining remaining compute once graphics finish. - Track active shader translation (`Shader::translating`) and scan a bounded 32-entry window in `Queue::pop` to avoid worker `OnceLock` convoys. - Single-pass GFX10 store analysis & cache helpers (`pipeline.rs`, `larp-pipeline/src/cache.rs`): - Merge `stores`, `stores_by_address`, and `stores_images` into a single `store_flags()` pass that decodes GFX10 bytecode once instead of 3x. - Cache shard directory creation in `larp_pipeline::Cache` and add `CacheKey::from_slices`, `Cache::read`, and `Cache::put`. Testing: - Added unit tests for `GraphicsState::describe()` equivalence/caching, `name_with_suffix` hash equivalence, sharded blob persistence/reopen, bounded heavy-compute scheduling, anti-convoy skipping, shader interleaving, and `CacheKey::from_slices`. - Verified `cargo test -p larp-pipeline -p larp-gpu`, `cargo check -p larp-gpu --features diagnostics`, and `cargo build --release -p larp`.
Optimize cold and warm D3D12 pipeline compilation while keeping existing
on-disk shader caches, scoped PSO blob caches, and pipeline catalog files
byte-for-byte compatible.

Changes:
- Root signature & geometry shader caching + zero-alloc warmup skip (`pipeline/host.rs`):
  - Cache `(ID3D12RootSignature, Arc<[u8]>)` by exact root layout and device
    using a thread-local scratch key, avoiding repeated
    `D3D12SerializeVersionedRootSignature` and `CreateRootSignature` calls.
  - Cache `GraphicsState::describe()` in a `OnceLock<String>` and format
    directly into a pre-sized buffer.
  - Eliminate per-pipeline `code_bytes()` DXIL copies and `" quad mask"`
    allocations by hashing `&[u8]` slices directly into stack `[u8; 32]` hex
    names (`blobs::name_hex_with_suffix`).
  - Check `blobs::skip_if_warming_on_disk` before constructing `Plan`,
    `Vec<Stage>`, `D3D12_GRAPHICS_PIPELINE_STATE_DESC`, or label strings.
  - Cache synthesized `rect_list_gs` DXIL by `(vs_hash, ps_hash, quad)` and
    gate `HostPipeline.state` formatting behind `feature = "diagnostics"`.

- Sharded blob directory index & multi-threaded writers (`pipeline/blobs.rs`):
  - Add a lazy 256-bucket directory index (`Shards`) backed by `read_dir`
    scans to replace ~100k+ per-file `metadata()` / `ENOENT` syscalls, and
    track created shard subdirectories to avoid repeated `create_dir_all`.
  - Compute blob header BLAKE3 checksums on compiling worker threads while
    blobs are hot in CPU cache instead of serializing hashing on one writer.
  - Replace the single blob writer thread with a 2-4 thread writer pool
    writing `[header, blob]` in a single `write_all` via reusable scratch
    buffers, updating the shard index before removing entries from `pending`.
  - Add `flush_queue` so `LARP_PRELOAD=1` exits promptly once blobs flush.

- Parallel catalog loading & smart queue scheduling (`pipeline/make.rs`, `pipeline/created.rs`):
  - Read catalog files concurrently, hash `created-shaders.bin` containers in
    parallel, store each listed record's stream subobjects in one flat buffer
    instead of per-subobject `Vec<u8>` allocations, build `Pending` entries in
    parallel waves, interleave graphics by primary shader hash, and batch
    `SHARED` / `QUEUE` insertions.
  - Cap concurrent heavy compute compiles (`>= 96 KiB`, largest-first) and
    total compute workers while graphics pipelines are queued so graphics
    stream in parallel without thrashing memory/L3/driver compiler, while
    keeping idle workers busy draining remaining compute once graphics finish.
  - Track active shader translation (`Shader::translating`) and scan a bounded
    32-entry window in `Queue::pop` to avoid worker `OnceLock` convoys.

- Single-pass GFX10 store analysis & cache helpers (`pipeline.rs`, `larp-pipeline/src/cache.rs`):
  - Merge `stores`, `stores_by_address`, and `stores_images` into a single
    `store_flags()` pass that decodes GFX10 bytecode once instead of 3x.
  - Cache shard directory creation in `larp_pipeline::Cache` and add
    `CacheKey::from_slices`, `Cache::read`, and `Cache::put`.

Testing:
- Added unit tests for `GraphicsState::describe()` equivalence/caching,
  `name_with_suffix` hash equivalence, sharded blob persistence/reopen,
  bounded heavy-compute scheduling, anti-convoy skipping, shader interleaving,
  and `CacheKey::from_slices`.
- Verified `cargo test -p larp-pipeline -p larp-gpu`, `cargo check -p larp-gpu
  --features diagnostics`, and `cargo build --release -p larp`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-06 02:31:10 +00:00
Author
Owner

@⁠christopear on GitHub · 2026-12-06 02:48 UTC · original

Independent Proton result for the shard index

I timed just Store::on_disk in the parent (459db13) and this change (3d7c1f4). The first lookup pass over a populated directory benefits substantially when most keys are queried. For a smaller subset, the first scan costs about as much as the direct lookups here.

Median elapsed milliseconds across six fresh processes per version, alternating which version ran first in each pair. Every pass returned the expected hit count.

Keys queried out of 8,192 Pass on this Store Parent PR
All First 1,337.12 92.23
All Repeat 1,248.50 0.89
Every 16th (512) First 77.73 83.55
Every 16th (512) Repeat 78.42 0.20

The first full pass ranged from 1,161–1,848 ms on the parent and 58–150 ms here. The first sparse ranges overlap (71–138 and 50–95 ms). I wouldn't infer a sparse regression from that difference. Each workload starts with a fresh Store. The repeat reuses its index.

Windows MSVC release test under Proton Experimental, one caller, synthetic framed entries on memory-backed storage. Files were freshly written before timing, so filesystem caches were warm. This isolates lookup and index construction. It excludes queue scheduling, reading blob payloads, driver creation and gameplay. A useful next measurement would be worker wall time when multiple workers first touch the same shards.

Separately, on a clean build of the PR head under Proton, 37 larp-gpu library tests and one larp-pipeline library test passed, plus five opt-in D3D12 tests. I skipped the native Windows identity test and the populated-cache timing test.

Reproduction for either revision

Append this test to crates/larp-gpu/src/pipeline/blobs/tests.rs and run the release larp-gpu library test filtered to compare_shard_lookup with --nocapture. The printed times are microseconds.


#[test]
fn compare_shard_lookup() {
    let root = std::env::temp_dir().join(format!("lookup-{}", std::process::id()));
    fs::create_dir(&root).unwrap();
    let keys: Vec<_> = (0u32..8192)
        .map(|i| name("graphics", b"root", &[&i.to_le_bytes()], "state"))
        .collect();
    let store = disk(&root, A);
    let dir = store.entries.as_ref().unwrap();
    for key in &keys {
        let p = path_of(dir, key);
        fs::create_dir_all(p.parent().unwrap()).unwrap();
        let data = b"fixture";
        fs::write(p, [header(data).as_slice(), data].concat()).unwrap();
    }
    for stride in [1usize, 16] {
        let store = disk(&root, A);
        for pass in 0..2 {
            let start = std::time::Instant::now();
            let hits = keys.iter().step_by(stride).filter(|key| store.on_disk(key)).count();
            let elapsed = start.elapsed().as_micros();
            assert_eq!(hits, keys.len() / stride);
            println!("LOOKUP {stride} {pass} {hits} {elapsed}");
        }
    }
    fs::remove_dir_all(root).unwrap();
}
**@⁠christopear** on GitHub · 2026-12-06 02:48 UTC · [original](https://github.com/gamingwithhomie/larp/pull/552#issuecomment-7450223468) **Independent Proton result for the shard index** I timed just `Store::on_disk` in the parent (`459db13`) and this change (`3d7c1f4`). The first lookup pass over a populated directory benefits substantially when most keys are queried. For a smaller subset, the first scan costs about as much as the direct lookups here. Median elapsed milliseconds across six fresh processes per version, alternating which version ran first in each pair. Every pass returned the expected hit count. | Keys queried out of 8,192 | Pass on this Store | Parent | PR | |---|---|---:|---:| | All | First | 1,337.12 | 92.23 | | All | Repeat | 1,248.50 | 0.89 | | Every 16th (512) | First | 77.73 | 83.55 | | Every 16th (512) | Repeat | 78.42 | 0.20 | The first full pass ranged from 1,161–1,848 ms on the parent and 58–150 ms here. The first sparse ranges overlap (71–138 and 50–95 ms). I wouldn't infer a sparse regression from that difference. Each workload starts with a fresh Store. The repeat reuses its index. Windows MSVC release test under Proton Experimental, one caller, synthetic framed entries on memory-backed storage. Files were freshly written before timing, so filesystem caches were warm. This isolates lookup and index construction. It excludes queue scheduling, reading blob payloads, driver creation and gameplay. A useful next measurement would be worker wall time when multiple workers first touch the same shards. Separately, on a clean build of the PR head under Proton, 37 larp-gpu library tests and one larp-pipeline library test passed, plus five opt-in D3D12 tests. I skipped the native Windows identity test and the populated-cache timing test. <details> <summary>Reproduction for either revision</summary> Append this test to `crates/larp-gpu/src/pipeline/blobs/tests.rs` and run the release larp-gpu library test filtered to `compare_shard_lookup` with `--nocapture`. The printed times are microseconds. ```rust #[test] fn compare_shard_lookup() { let root = std::env::temp_dir().join(format!("lookup-{}", std::process::id())); fs::create_dir(&root).unwrap(); let keys: Vec<_> = (0u32..8192) .map(|i| name("graphics", b"root", &[&i.to_le_bytes()], "state")) .collect(); let store = disk(&root, A); let dir = store.entries.as_ref().unwrap(); for key in &keys { let p = path_of(dir, key); fs::create_dir_all(p.parent().unwrap()).unwrap(); let data = b"fixture"; fs::write(p, [header(data).as_slice(), data].concat()).unwrap(); } for stride in [1usize, 16] { let store = disk(&root, A); for pass in 0..2 { let start = std::time::Instant::now(); let hits = keys.iter().step_by(stride).filter(|key| store.on_disk(key)).count(); let elapsed = start.elapsed().as_micros(); assert_eq!(hits, keys.len() / stride); println!("LOOKUP {stride} {pass} {hits} {elapsed}"); } } fs::remove_dir_all(root).unwrap(); } ``` </details>
Author
Owner

@⁠professional-pussy-eater on GitHub · 2026-12-06 02:59 UTC · original

Thanks for the independent Proton benchmark and D3D12 test verification!

Prompted by your note on multi-worker contention, I also removed a global mutex bottleneck on warm lookups in blobs.rs: Store::on_disk() and read() now check an Acquire/Release AtomicUsize length mirror before acquiring pending's Mutex (skipping the lock completely when nothing is pending persistence).

Here are the native Windows MSVC release measurements comparing parent (459db13) vs this PR across single-caller and multi-worker workloads (including worst-case lockstep same-shard collisions where all workers hit 00..ff in lockstep behind a Barrier):

Median wall-clock milliseconds across 6 fresh processes per version (alternating parent/PR order), 8,192 synthetic framed entries per process, every pass verified against expected hit counts:

Workload (8,192 keys unless noted) Pass on this Store Parent (ms) PR (ms) Speedup
1 thread, all (8,192) First 241.26 (232.20–525.71) 26.58 (21.79–38.87) 9.1×
1 thread, all (8,192) Repeat 238.09 (222.34–259.34) 0.47 (0.43–1.69) 502.8×
1 thread, every 16th (512) First 15.00 (14.11–18.22) 17.92 (16.18–26.31) 0.8×
1 thread, every 16th (512) Repeat 14.49 (13.48–17.14) 0.08 (0.05–0.15) 186.9×
8 workers, interleaved (all 8,192) First 45.82 (43.41–48.99) 4.71 (4.34–5.75) 9.7×
8 workers, interleaved (all 8,192) Repeat 45.66 (43.97–50.55) 0.24 (0.21–0.29) 191.5×
8 workers, same-shard burst (all 8,192) First 46.97 (44.94–59.47) 24.16 (23.28–30.64) 1.9×
8 workers, same-shard burst (all 8,192) Repeat 46.53 (44.21–66.51) 0.32 (0.23–0.47) 146.8×
12 workers, same-shard burst (all 8,192) First 38.53 (36.68–64.04) 26.15 (23.49–35.85) 1.5×
12 workers, same-shard burst (all 8,192) Repeat 40.33 (38.17–86.06) 0.25 (0.16–0.42) 163.6×

Key takeaways:

  • Realistic multi-worker startup (8 workers interleaved): first pass drops from 45.82 ms → 4.71 ms (9.7× faster, scaling ~5.6× over single-threaded 26.58 ms across the 256 independent OnceLock shards).
  • Worst-case lockstep same-shard collisions (8 and 12 workers): wall time stays flat at the ~24–26 ms single-scan floor (still 1.5×–1.9× faster than parent on pass 0, and 147×–164× faster on repeat) with no contention amplification as worker count increases.
Reproduction for either revision

Append to crates/larp-gpu/src/pipeline/blobs/tests.rs and run in release with compare_shard_lookup_mt --ignored --nocapture:

#[test]
#[ignore = "multi-worker shard lookup benchmark"]
fn compare_shard_lookup_mt() {
    use std::sync::Barrier;

    let root = std::env::temp_dir().join(format!("lookup-mt-{}", std::process::id()));
    let _ = fs::remove_dir_all(&root);
    fs::create_dir(&root).unwrap();
    let keys: Vec<String> = (0u32..8192)
        .map(|i| name("graphics", b"root", &[&i.to_le_bytes()], "state"))
        .collect();
    let mut sorted = keys.clone();
    sorted.sort();
    let store = disk(&root, A);
    let dir = store.entries.as_ref().unwrap();
    for key in &keys {
        let p = path_of(dir, key);
        fs::create_dir_all(p.parent().unwrap()).unwrap();
        let data = b"fixture";
        fs::write(p, [header(data).as_slice(), data].concat()).unwrap();
    }
    drop(store);

    let run = |label: &str, workers: usize, list: &[String], stride: usize| {
        let store = disk(&root, A);
        let expected = list.iter().step_by(stride).count();
        for pass in 0..2 {
            let elapsed = if workers == 1 {
                let start = Instant::now();
                let hits = list
                    .iter()
                    .step_by(stride)
                    .filter(|key| store.on_disk(key))
                    .count();
                assert_eq!(hits, expected);
                start.elapsed().as_micros()
            } else {
                let barrier = Barrier::new(workers + 1);
                let hits = std::sync::atomic::AtomicUsize::new(0);
                let mut elapsed = 0u128;
                std::thread::scope(|scope| {
                    let mut handles = Vec::with_capacity(workers);
                    for tid in 0..workers {
                        let store = &store;
                        let barrier = &barrier;
                        let hits = &hits;
                        handles.push(scope.spawn(move || {
                            barrier.wait();
                            let local = list
                                .iter()
                                .skip(tid)
                                .step_by(workers)
                                .filter(|key| store.on_disk(key))
                                .count();
                            hits.fetch_add(local, Relaxed);
                        }));
                    }
                    barrier.wait();
                    let start = Instant::now();
                    for h in handles {
                        h.join().unwrap();
                    }
                    elapsed = start.elapsed().as_micros();
                });
                assert_eq!(hits.load(Relaxed), expected);
                elapsed
            };
            println!("BENCH {label} {pass} {expected} {elapsed}");
        }
    };

    run("single_all", 1, &keys, 1);
    run("single_sparse", 1, &keys, 16);
    run("workers8_interleaved", 8, &keys, 1);
    run("workers8_same_shard", 8, &sorted, 1);
    run("workers12_same_shard", 12, &sorted, 1);
    fs::remove_dir_all(root).unwrap();
}
**@⁠professional-pussy-eater** on GitHub · 2026-12-06 02:59 UTC · [original](https://github.com/gamingwithhomie/larp/pull/552#issuecomment-7450357987) Thanks for the independent Proton benchmark and D3D12 test verification! Prompted by your note on multi-worker contention, I also removed a global mutex bottleneck on warm lookups in `blobs.rs`: `Store::on_disk()` and `read()` now check an `Acquire`/`Release` `AtomicUsize` length mirror before acquiring `pending`'s `Mutex` (skipping the lock completely when nothing is pending persistence). Here are the native Windows MSVC release measurements comparing parent (`459db13`) vs this PR across single-caller and multi-worker workloads (including worst-case lockstep same-shard collisions where all workers hit `00`..`ff` in lockstep behind a `Barrier`): Median wall-clock milliseconds across 6 fresh processes per version (alternating parent/PR order), 8,192 synthetic framed entries per process, every pass verified against expected hit counts: | Workload (8,192 keys unless noted) | Pass on this Store | Parent (ms) | PR (ms) | Speedup | |---|---|---:|---:|---:| | 1 thread, all (8,192) | First | 241.26 (232.20–525.71) | 26.58 (21.79–38.87) | 9.1× | | 1 thread, all (8,192) | Repeat | 238.09 (222.34–259.34) | 0.47 (0.43–1.69) | 502.8× | | 1 thread, every 16th (512) | First | 15.00 (14.11–18.22) | 17.92 (16.18–26.31) | 0.8× | | 1 thread, every 16th (512) | Repeat | 14.49 (13.48–17.14) | 0.08 (0.05–0.15) | 186.9× | | 8 workers, interleaved (all 8,192) | First | 45.82 (43.41–48.99) | 4.71 (4.34–5.75) | 9.7× | | 8 workers, interleaved (all 8,192) | Repeat | 45.66 (43.97–50.55) | 0.24 (0.21–0.29) | 191.5× | | 8 workers, same-shard burst (all 8,192) | First | 46.97 (44.94–59.47) | 24.16 (23.28–30.64) | 1.9× | | 8 workers, same-shard burst (all 8,192) | Repeat | 46.53 (44.21–66.51) | 0.32 (0.23–0.47) | 146.8× | | 12 workers, same-shard burst (all 8,192) | First | 38.53 (36.68–64.04) | 26.15 (23.49–35.85) | 1.5× | | 12 workers, same-shard burst (all 8,192) | Repeat | 40.33 (38.17–86.06) | 0.25 (0.16–0.42) | 163.6× | Key takeaways: - **Realistic multi-worker startup (8 workers interleaved)**: first pass drops from **45.82 ms → 4.71 ms** (**9.7× faster**, scaling ~5.6× over single-threaded `26.58 ms` across the 256 independent `OnceLock` shards). - **Worst-case lockstep same-shard collisions (8 and 12 workers)**: wall time stays flat at the ~24–26 ms single-scan floor (still **1.5×–1.9× faster** than parent on pass 0, and **147×–164× faster** on repeat) with no contention amplification as worker count increases. <details> <summary>Reproduction for either revision</summary> Append to `crates/larp-gpu/src/pipeline/blobs/tests.rs` and run in release with `compare_shard_lookup_mt --ignored --nocapture`: ```rust #[test] #[ignore = "multi-worker shard lookup benchmark"] fn compare_shard_lookup_mt() { use std::sync::Barrier; let root = std::env::temp_dir().join(format!("lookup-mt-{}", std::process::id())); let _ = fs::remove_dir_all(&root); fs::create_dir(&root).unwrap(); let keys: Vec<String> = (0u32..8192) .map(|i| name("graphics", b"root", &[&i.to_le_bytes()], "state")) .collect(); let mut sorted = keys.clone(); sorted.sort(); let store = disk(&root, A); let dir = store.entries.as_ref().unwrap(); for key in &keys { let p = path_of(dir, key); fs::create_dir_all(p.parent().unwrap()).unwrap(); let data = b"fixture"; fs::write(p, [header(data).as_slice(), data].concat()).unwrap(); } drop(store); let run = |label: &str, workers: usize, list: &[String], stride: usize| { let store = disk(&root, A); let expected = list.iter().step_by(stride).count(); for pass in 0..2 { let elapsed = if workers == 1 { let start = Instant::now(); let hits = list .iter() .step_by(stride) .filter(|key| store.on_disk(key)) .count(); assert_eq!(hits, expected); start.elapsed().as_micros() } else { let barrier = Barrier::new(workers + 1); let hits = std::sync::atomic::AtomicUsize::new(0); let mut elapsed = 0u128; std::thread::scope(|scope| { let mut handles = Vec::with_capacity(workers); for tid in 0..workers { let store = &store; let barrier = &barrier; let hits = &hits; handles.push(scope.spawn(move || { barrier.wait(); let local = list .iter() .skip(tid) .step_by(workers) .filter(|key| store.on_disk(key)) .count(); hits.fetch_add(local, Relaxed); })); } barrier.wait(); let start = Instant::now(); for h in handles { h.join().unwrap(); } elapsed = start.elapsed().as_micros(); }); assert_eq!(hits.load(Relaxed), expected); elapsed }; println!("BENCH {label} {pass} {expected} {elapsed}"); } }; run("single_all", 1, &keys, 1); run("single_sparse", 1, &keys, 16); run("workers8_interleaved", 8, &keys, 1); run("workers8_same_shard", 8, &sorted, 1); run("workers12_same_shard", 12, &sorted, 1); fs::remove_dir_all(root).unwrap(); } ``` </details>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/552/head:github-bot/gh-552'
git switch 'github-bot/gh-552'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-552'
git switch 'github-bot/gh-552'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-552'
git switch 'github-bot/gh-552'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-552'
git switch 'main'
git merge --squash 'github-bot/gh-552'
git switch 'main'
git merge --ff-only 'github-bot/gh-552'
git switch 'main'
git merge 'github-bot/gh-552'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.