Skip to content

docs(audits): pick DashMap or sharded for ParallelDeltaApplier files (BR-3j.a) - #4600

Merged
oferchen merged 1 commit into
masterfrom
docs/br-3j-a-dashmap-vs-sharded-audit
May 20, 2026
Merged

oferchen merged 1 commit into
masterfrom
docs/br-3j-a-dashmap-vs-sharded-audit

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Read-only audit for feat(core): complete server invocation builder with all flag forwarding #2503 (BR-3j.a). Evaluates replacing the outer Mutex<HashMap<FileNdx, Arc<Mutex<FileSlot>>>> on ParallelDeltaApplier at crates/engine/src/concurrent_delta/parallel_apply.rs:252 with either dashmap::DashMap or a hand-rolled sharded Mutex<HashMap>.
  • Pick: DashMap. Per-chunk hot path is read-and-clone-Arc; DashMap's per-shard RwLock lets concurrent readers proceed on the same shard, the Entry API removes the TOCTOU window in register_file, and the workspace already runs dashmap = "6.1" (MSRV 1.65, well below our 1.88 pin) in the daemon and as a dev-dep on the engine crate.
  • Includes side-by-side criteria table, before/after API sketch for slot_for/register_file/finish_file, BR-3j.c gotchas (Entry vs contains+insert, Ref guard lifetime, !Send, dev-dep promotion), and the MSRV check.

Test plan

  • Audit file lives under docs/audits/ and follows the existing br-*-YYYY-MM-DD.md naming pattern.
  • No source files modified - read-only audit.
  • cargo fmt --all clean on the audit-only diff.
  • All file:line references resolve against the current master snapshot.
  • MSRV verified via cargo info dashmap (6.1 declares rust-version = 1.65; workspace pins 1.88 in rust-toolchain.toml).

Read-only audit for #2503. Evaluates DashMap vs hand-rolled sharded
Mutex<HashMap> as the replacement for the outer mutex on
ParallelDeltaApplier.files. Picks DashMap and sketches the API shape
for BR-3j.c to implement against.
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label May 20, 2026
@oferchen
oferchen merged commit f300f01 into master May 20, 2026
10 checks passed
@oferchen
oferchen deleted the docs/br-3j-a-dashmap-vs-sharded-audit branch May 20, 2026 20:24
oferchen added a commit that referenced this pull request May 20, 2026
…4612)

BR-3j.a (PR #4600) selected DashMap to replace the
`Mutex<HashMap<FileNdx, Arc<Mutex<FileSlot>>>>` at
`crates/engine/src/concurrent_delta/parallel_apply.rs:252`. Today
`dashmap` is only an engine dev-dep; this commit promotes it to
`[dependencies]` (unconditional, matching the audit recommendation)
so BR-3j.c can perform the source migration in a follow-up PR.

No source-code changes here.
oferchen added a commit that referenced this pull request May 21, 2026
BR-3j.a (PR #4600) selected DashMap to replace the outer
`Mutex<HashMap<FileNdx, Arc<Mutex<FileSlot>>>>` map in
`ParallelDeltaApplier`. The outer mutex serialised every per-chunk slot
lookup behind a single global lock, defeating the per-file fanout the
rest of the applier was built around (#2503, BR-3j.c).

This commit performs the source migration:

- `files: Mutex<HashMap<...>>` -> `files: DashMap<FileNdx, Arc<Mutex<FileSlot>>>`
- `register_file` uses `Entry::Vacant`/`Entry::Occupied` and pre-builds
  the slot Arc outside the shard guard so the reorder-buffer allocation
  never widens the lock window.
- `slot_for` clones the Arc and drops the shard read guard at the end
  of the expression; callers never see the DashMap guard, so they
  cannot accidentally hold it across the per-file mutex lock or a
  rayon dispatch.
- `finish_file` uses `DashMap::remove` which returns the owned `(K, V)`
  and drops the shard guard before `Arc::try_unwrap`.
- `Debug` reads `self.files.len()` directly.

The inner `Mutex<FileSlot>` is preserved: it remains the sole gate for
per-file writes so submission order is still enforced through the
`ReorderBuffer`. Public API of `ParallelDeltaApplier` is unchanged.

Adds a concurrency stress test
(`crates/engine/tests/parallel_apply_concurrent.rs`, BR-3j.e #2507)
that spawns N rayon workers each picking a random FileNdx from a pool
of 1000 files and verifies bytes_written matches expected. A second
test races registration and dispatch on overlapping files and asserts
the applier surfaces only typed errors (never panics or corrupts).
On the dev box the stress test reports ~2.17M ops/sec (8 workers,
1000 files, 10000 ops).

No unsafe code added. No clippy waivers. `cargo build -p engine
--no-default-features` still compiles. Targeted nextest runs for
`concurrent_delta` and `parallel_apply` binaries all pass (340 tests
including the 2 new stress tests).
oferchen added a commit that referenced this pull request May 21, 2026
…ap (#4634)

BR-3j.a (PR #4600) selected DashMap to replace the outer
`Mutex<HashMap<FileNdx, Arc<Mutex<FileSlot>>>>` map in
`ParallelDeltaApplier`. The outer mutex serialised every per-chunk slot
lookup behind a single global lock, defeating the per-file fanout the
rest of the applier was built around (#2503, BR-3j.c).

This commit performs the source migration:

- `files: Mutex<HashMap<...>>` -> `files: DashMap<FileNdx, Arc<Mutex<FileSlot>>>`
- `register_file` uses `Entry::Vacant`/`Entry::Occupied` and pre-builds
  the slot Arc outside the shard guard so the reorder-buffer allocation
  never widens the lock window.
- `slot_for` clones the Arc and drops the shard read guard at the end
  of the expression; callers never see the DashMap guard, so they
  cannot accidentally hold it across the per-file mutex lock or a
  rayon dispatch.
- `finish_file` uses `DashMap::remove` which returns the owned `(K, V)`
  and drops the shard guard before `Arc::try_unwrap`.
- `Debug` reads `self.files.len()` directly.

The inner `Mutex<FileSlot>` is preserved: it remains the sole gate for
per-file writes so submission order is still enforced through the
`ReorderBuffer`. Public API of `ParallelDeltaApplier` is unchanged.

Adds a concurrency stress test
(`crates/engine/tests/parallel_apply_concurrent.rs`, BR-3j.e #2507)
that spawns N rayon workers each picking a random FileNdx from a pool
of 1000 files and verifies bytes_written matches expected. A second
test races registration and dispatch on overlapping files and asserts
the applier surfaces only typed errors (never panics or corrupts).
On the dev box the stress test reports ~2.17M ops/sec (8 workers,
1000 files, 10000 ops).

No unsafe code added. No clippy waivers. `cargo build -p engine
--no-default-features` still compiles. Targeted nextest runs for
`concurrent_delta` and `parallel_apply` binaries all pass (340 tests
including the 2 new stress tests).
oferchen added a commit that referenced this pull request Aug 24, 2026
…4600)

Read-only audit for #2503. Evaluates DashMap vs hand-rolled sharded
Mutex<HashMap> as the replacement for the outer mutex on
ParallelDeltaApplier.files. Picks DashMap and sketches the API shape
for BR-3j.c to implement against.
oferchen added a commit that referenced this pull request Aug 24, 2026
…4612)

BR-3j.a (PR #4600) selected DashMap to replace the
`Mutex<HashMap<FileNdx, Arc<Mutex<FileSlot>>>>` at
`crates/engine/src/concurrent_delta/parallel_apply.rs:252`. Today
`dashmap` is only an engine dev-dep; this commit promotes it to
`[dependencies]` (unconditional, matching the audit recommendation)
so BR-3j.c can perform the source migration in a follow-up PR.

No source-code changes here.
oferchen added a commit that referenced this pull request Aug 24, 2026
…ap (#4634)

BR-3j.a (PR #4600) selected DashMap to replace the outer
`Mutex<HashMap<FileNdx, Arc<Mutex<FileSlot>>>>` map in
`ParallelDeltaApplier`. The outer mutex serialised every per-chunk slot
lookup behind a single global lock, defeating the per-file fanout the
rest of the applier was built around (#2503, BR-3j.c).

This commit performs the source migration:

- `files: Mutex<HashMap<...>>` -> `files: DashMap<FileNdx, Arc<Mutex<FileSlot>>>`
- `register_file` uses `Entry::Vacant`/`Entry::Occupied` and pre-builds
  the slot Arc outside the shard guard so the reorder-buffer allocation
  never widens the lock window.
- `slot_for` clones the Arc and drops the shard read guard at the end
  of the expression; callers never see the DashMap guard, so they
  cannot accidentally hold it across the per-file mutex lock or a
  rayon dispatch.
- `finish_file` uses `DashMap::remove` which returns the owned `(K, V)`
  and drops the shard guard before `Arc::try_unwrap`.
- `Debug` reads `self.files.len()` directly.

The inner `Mutex<FileSlot>` is preserved: it remains the sole gate for
per-file writes so submission order is still enforced through the
`ReorderBuffer`. Public API of `ParallelDeltaApplier` is unchanged.

Adds a concurrency stress test
(`crates/engine/tests/parallel_apply_concurrent.rs`, BR-3j.e #2507)
that spawns N rayon workers each picking a random FileNdx from a pool
of 1000 files and verifies bytes_written matches expected. A second
test races registration and dispatch on overlapping files and asserts
the applier surfaces only typed errors (never panics or corrupts).
On the dev box the stress test reports ~2.17M ops/sec (8 workers,
1000 files, 10000 ops).

No unsafe code added. No clippy waivers. `cargo build -p engine
--no-default-features` still compiles. Targeted nextest runs for
`concurrent_delta` and `parallel_apply` binaries all pass (340 tests
including the 2 new stress tests).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant