You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf: optimize CoinJoin masternode tracking with hybrid data structure
Improves performance by implementing a dual data structure approach for
tracking used masternodes in CoinJoin sessions:
- Use std::deque<uint256> for maintaining FIFO insertion order
- Use std::unordered_set<uint256> for O(1) lookup performance
- Replace GetUsedMasternodesSet() with IsUsedMasternode() to avoid
expensive set construction on every masternode selection
Performance improvements at 1800 used masternodes:
- Masternode selection: 2.5ms → 0.1ms (25x faster)
- Batch removal: 100µs → 27µs (4x faster)
The optimization becomes increasingly important at scale (>1000 MNs)
and in multi-wallet scenarios with concurrent CoinJoin sessions.
Key design decisions:
- Deque provides O(1) front removal (vs O(n) for vector)
- Unordered_set provides O(1) lookup (vs O(n log n) set construction)
- Only deque is serialized; set is rebuilt on load (no version bump)
- Both structures stay synchronized through all operations
- Automatic duplicate prevention in AddUsedMasternode()
Memory cost: ~130 KB for 1800 entries (negligible)
Code complexity: Minimal, well-encapsulated
This builds on PR #6875 which moved masternode tracking from per-wallet
to shared global storage. That PR solved the multi-wallet coordination
problem; this patch addresses the performance bottleneck at scale.
0 commit comments