Skip to content

Optimize batch reconstruction protocol for improved concurrency#66

Draft
Mikerah wants to merge 1 commit intomainfrom
optimize-batch-recon
Draft

Optimize batch reconstruction protocol for improved concurrency#66
Mikerah wants to merge 1 commit intomainfrom
optimize-batch-recon

Conversation

@Mikerah
Copy link
Contributor

@Mikerah Mikerah commented Jan 9, 2026

Summary

  • Replace nested Arc<Mutex<HashMap>> with Arc<DashMap> for single-lock session access
  • Add HashSet for O(1) deduplication instead of O(n) linear search
  • Add AtomicBool guards to prevent race conditions during interpolation
  • Move expensive interpolation operations outside lock scope
  • Convert clear_entire_store, clear_store, and get_or_create_store to sync methods

Performance Improvements

Operation Before After
Session lookup 2 locks 1 lock
Deduplication O(n) O(1)
Interpolation Blocking Non-blocking

Race Condition Prevention

Scenario Prevention Mechanism
Two messages reach threshold simultaneously AtomicBool::compare_exchange ensures exactly one caller wins
Message arrives during interpolation Interpolation uses cloned snapshot; live vector safe to modify
Double interpolation trigger Atomic flag checked before AND after threshold

Test plan

  • Run batch_recon tests
  • Run full test suite
  • Run tests with multiple threads (RUST_TEST_THREADS=8)

🤖 Generated with Claude Code

- Replace nested Arc<Mutex<HashMap>> with Arc<DashMap> for single-lock session access
- Add HashSet for O(1) deduplication instead of O(n) linear search
- Add AtomicBool guards to prevent race conditions during interpolation
- Move expensive interpolation operations outside lock scope
- Convert clear_entire_store, clear_store, and get_or_create_store to sync methods

Performance improvements:
- Session lookup: 2 locks → 1 lock
- Deduplication: O(n) → O(1)
- Interpolation: blocking → non-blocking

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant