Skip to content

Optimize vector clock merge/compare/increment and binary serialization#32

Merged
dexcompiler merged 3 commits intomainfrom
vector-clock-perf-improvements
Feb 8, 2026
Merged

Optimize vector clock merge/compare/increment and binary serialization#32
dexcompiler merged 3 commits intomainfrom
vector-clock-perf-improvements

Conversation

@dexcompiler
Copy link
Copy Markdown
Owner

This PR improves VectorClock performance by reducing allocations and avoiding repeated lookups in the most common operations (Compare(VectorClock), Merge(VectorClock), Increment(ushort)) and by using BinaryPrimitives for big-endian binary encoding/decoding. No behavior or wire-format changes are intended.
Changes:

  • Compare(VectorClock): replaced HashSet + repeated Get( ) calls with a single linear merge-style walk over both sorted node-id arrays (allocation-free, O(n+m)).
  • Merge(VectorClock): removed List<T> usage and ToArray( ) copies; now merges directly into pre-allocated arrays and trims to actual size.
  • Increment(ushort): when incrementing an existing node, share the immutable node-id array and copy only the counters array; small copy optimizations for insert case.
  • WriteTo(Span<byte>) / ReadFrom(ReadOnlySpan<byte>): use System.Buffers.Binary.BinaryPrimitives for big-endian reads/writes (same on-wire format).
  • Docs: updated complexity claim in the VectorClock XML comment from O(n) to O(n+m).
  • Repo guidance: updated .github/copilot-instructions.md to prefer mathematically precise complexity docs during refactors while preserving semantics/wire format.

@dexcompiler
Copy link
Copy Markdown
Owner Author

@copilot review

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 8, 2026

@dexcompiler I've opened a new pull request, #33, to work on those changes. Once the pull request is ready, I'll request review from you.

Code review completed - VectorClock optimizations verified
@dexcompiler dexcompiler merged commit 979abbf into main Feb 8, 2026
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.

2 participants