Skip to content

v0.4.0 release

Choose a tag to compare

@homer6 homer6 released this 18 Feb 18:55
· 30 commits to main since this release

automerge-cpp v0.4.0 — Performance & Parallelism

The 0.4.0 release introduces robust multi-threading, execution model. This version enables near-linear scaling for read-heavy workloads and significant throughput improvements for batch mutations across multi-core systems.


Thread Safety & Concurrent Access

The Document class is now fully thread-safe, allowing safe usage in multi-threaded environments like high-concurrency servers.

  • Read-Write Locking: Implemented internal synchronization using std::shared_mutex. Public API methods automatically manage locking:
    • N Concurrent Readers: Methods like get, text, keys, and save utilize shared locks.
    • Exclusive Writers: Mutation methods like transact and merge utilize exclusive locks.
  • Lock-Free Read Path: Introduced set_read_locking(false) for scenarios where the caller can guarantee no concurrent writers. This eliminates shared_mutex cache-line contention, delivering up to 13.5x parallel scaling on 30-core systems.
  • Shared Thread Pool: Documents can now share a work-stealing thread pool via the new constructor Document(std::shared_ptr<thread_pool>).

Parallel Performance Improvements

This release focuses on "Phase 11: Performance and Parallelism," delivering massive speedups for historical data access and document persistence.

Key Optimization Metrics (30-core Linux Xeon)

Operation Sequential Parallel Speedup
Get (100K keys, lock-free) 7.1 M ops/s 95.0 M ops/s 13.5x
Save (500 documents) 95 K docs/s 806 K docs/s 8.4x
Time Travel (get_at) 130 K ops/s 2.88 M ops/s 22.1x
Sync Protocol 4.7 K ops/s 26.4 K ops/s 5.6x

Internal Parallelism

  • Work-Stealing Infrastructure: Integrated Barak Shoshany's header-only BS::thread_pool.
  • Performance Caching: * Change Hash Cache: Eliminates redundant SHA-256 computations during sync and time travel (22x faster historical reads).
    • Actor Table Cache: Speeds up large document saves by 1.2x.
  • Low-Latency Dispatch: Configured internal workers to yield instead of sleep, reducing latency for high-frequency small tasks.

New Demonstrations & Benchmarks

Two new focus-built examples showcase the v0.4.0 threading architecture:

  • thread_safe_demo: Illustrates simultaneous readers and writers on a single document, including simultaneous text appends and deterministic concurrent saves.
  • parallel_perf_demo: Demonstrates the power of monoid-associative merging through parallel tree-reduction of 100 peers and parallel sync of 50 document pairs.

The benchmark suite has expanded from 26 to 32 benchmarks, now covering parallel scaling efficiency and hardware utilization.


Infrastructure & Maintenance

  • Code Quality: Added // NOLINT annotations and explanatory documentation for intentional edge cases in the thread pool logic.
  • CI Updates: Replaced std::jthread usage with std::thread and explicit join loops to maintain maximum compatibility across older toolchains and the FreeBSD CI environment.
  • Dependency Management: Removed the Taskflow dependency in favor of the lightweight, header-only thread pool.

Project Status

  • Tests: 281 passing tests (7 new thread-safety specific tests).
  • Next Steps: Remaining Phase 11 items including Fenwick tree integration for $O(\log n)$ list operations and hardware-accelerated SHA-256.