{"id":45012487,"url":"https://github.com/homer6/automerge-cpp","last_synced_at":"2026-02-24T05:00:59.084Z","repository":{"id":339093507,"uuid":"1160442061","full_name":"homer6/automerge-cpp","owner":"homer6","description":"A modern C++23 implementation of Automerge — a conflict-free replicated data type (CRDT) library for building collaborative applications.","archived":false,"fork":false,"pushed_at":"2026-02-19T06:01:31.000Z","size":713,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-20T03:03:46.849Z","etag":null,"topics":["cpp","cpp23-library","crdts"],"latest_commit_sha":null,"homepage":"https://homer6.github.io/automerge-cpp/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/homer6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-18T00:05:21.000Z","updated_at":"2026-02-19T05:57:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/homer6/automerge-cpp","commit_stats":null,"previous_names":["homer6/automerge-cpp"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/homer6/automerge-cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/homer6%2Fautomerge-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/homer6%2Fautomerge-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/homer6%2Fautomerge-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/homer6%2Fautomerge-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/homer6","download_url":"https://codeload.github.com/homer6/automerge-cpp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/homer6%2Fautomerge-cpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29671513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T00:11:43.526Z","status":"online","status_checked_at":"2026-02-21T02:00:07.432Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","cpp23-library","crdts"],"created_at":"2026-02-19T00:04:12.803Z","updated_at":"2026-02-21T02:00:32.882Z","avatar_url":"https://github.com/homer6.png","language":"C++","readme":"# automerge-cpp\n\n![Linux](https://github.com/homer6/automerge-cpp/actions/workflows/linux.yml/badge.svg)\n![macOS](https://github.com/homer6/automerge-cpp/actions/workflows/macos.yml/badge.svg)\n![Windows](https://github.com/homer6/automerge-cpp/actions/workflows/windows.yml/badge.svg)\n![FreeBSD](https://github.com/homer6/automerge-cpp/actions/workflows/freebsd.yml/badge.svg)\n\nA modern C++23 implementation of [Automerge](https://automerge.org/) — a conflict-free\nreplicated data type (CRDT) library for building collaborative applications.\n\nThis is a **from-scratch** reimplementation, not a wrapper. It mirrors the upstream\nAutomerge semantics while embracing idiomatic C++23: algebraic types, ranges pipelines,\nstrong types, and APIs that make illegal states unrepresentable.\n\n**281 tests passing** across 8 implementation phases.\n\n## Quick Example\n\n```cpp\n#include \u003cautomerge-cpp/automerge.hpp\u003e\nnamespace am = automerge_cpp;\n\nint main() {\n    auto doc1 = am::Document{};\n    am::ObjId list_id;\n\n    doc1.transact([\u0026](auto\u0026 tx) {\n        tx.put(am::root, \"title\", std::string{\"Shopping List\"});\n        list_id = tx.put_object(am::root, \"items\", am::ObjType::list);\n        tx.insert(list_id, 0, std::string{\"Milk\"});\n        tx.insert(list_id, 1, std::string{\"Eggs\"});\n    });\n\n    // Fork and make concurrent edits\n    auto doc2 = doc1.fork();\n\n    doc1.transact([\u0026](auto\u0026 tx) {\n        tx.insert(list_id, 2, std::string{\"Bread\"});\n    });\n\n    doc2.transact([\u0026](auto\u0026 tx) {\n        tx.insert(list_id, 2, std::string{\"Butter\"});\n    });\n\n    // Merge — both edits preserved, no data loss\n    doc1.merge(doc2);\n    // list now contains: Milk, Eggs, Bread, Butter (deterministic order)\n\n    // Save to binary and reload\n    auto bytes = doc1.save();\n    auto loaded = am::Document::load(bytes);\n\n    // Time travel — read past state\n    auto heads_v1 = doc1.get_heads();\n    auto past = doc1.get_at(am::root, \"title\", heads_v1);\n}\n```\n\n## Features\n\n### Implemented\n\n- **CRDT data types**: Map, List, Text, Counter\n- **Conflict-free merging**: concurrent edits merge deterministically (RGA for lists/text)\n- **Fork and merge**: create independent document copies, merge them back\n- **Binary serialization**: `save()` / `load()` with upstream-compatible columnar encoding\n- **Sync protocol**: bloom filter-based peer-to-peer synchronization\n- **Patches**: incremental change notifications via `transact_with_patches()`\n- **Time travel**: read document state at any historical point (`get_at()`, `text_at()`, etc.)\n- **Cursors**: stable positions in lists/text that survive edits and merges\n- **Rich text marks**: range annotations (bold, italic, links) anchored by identity, not index\n- **Strong types**: `ActorId`, `ObjId`, `ChangeHash`, `OpId` never implicitly convert\n- **Type-safe values**: `std::variant`-based `ScalarValue` and `Value` types\n\n- **Columnar encoding**: upstream-compatible columnar op encoding with RLE, delta, and boolean encoders\n- **DEFLATE compression**: raw DEFLATE (no zlib/gzip header) for columns exceeding 256 bytes, matching upstream Rust format\n- **SHA-256 checksums**: chunk envelope with SHA-256 integrity validation\n- **Backward compatibility**: v1 format loading with automatic format detection\n\n- **Fuzz testing**: libFuzzer targets for `Document::load()`, LEB128 decode, and change chunk parsing\n- **Static analysis**: clang-tidy CI with `bugprone-*`, `performance-*`, and `clang-analyzer-*` checks\n- **Sanitizer CI**: Address Sanitizer + Undefined Behavior Sanitizer on all tests\n\n- **Thread safety**: `Document` is thread-safe via `std::shared_mutex` — N concurrent readers, exclusive writers\n- **Thread pool**: built-in work-stealing thread pool (Barak Shoshany's BS::thread_pool), shared across documents\n- **Lock-free reads**: `set_read_locking(false)` eliminates shared_mutex contention for read-heavy workloads (13.5x parallel scaling on 30 cores)\n- **Performance caching**: change hash cache (22x faster time travel), actor table cache (1.2x faster save)\n\n- **Doxygen documentation**: auto-generated API docs with GitHub Pages deployment\n\n## Performance\n\nRelease-build highlights (Intel Xeon Platinum 8358, 30 cores, Linux, GCC 13.3, `-O3 -march=native`):\n\n### Single-Threaded\n\n| Operation | Throughput |\n|-----------|------------|\n| Map put (batched) | 4.3 M ops/s |\n| Map get | 19.8 M ops/s |\n| Sync round trip | 23.6 K ops/s |\n| Time travel get_at | 2.9 M ops/s |\n| Merge (10+10 puts) | 241 K ops/s |\n| Cursor resolve | 1.8 M ops/s |\n| Save (100 keys) | 30.6 K ops/s |\n\n### Parallel Scaling (30 cores)\n\n| Operation | Sequential | Parallel | Speedup |\n|-----------|-----------|----------|---------|\n| Get (100K keys, lock-free) | 7.1 M ops/s | **95.0 M ops/s** | **13.5x** |\n| Get (1M keys, lock-free) | 5.7 M ops/s | **55.0 M ops/s** | **9.6x** |\n| Put (100K keys, sharded) | 2.0 M ops/s | **13.5 M ops/s** | **6.9x** |\n| Put (1M keys, sharded) | 1.7 M ops/s | **8.4 M ops/s** | **4.8x** |\n| Save 500 docs | 95 K docs/s | **806 K docs/s** | **8.4x** |\n| Load 500 docs | 48 K docs/s | **190 K docs/s** | **3.9x** |\n\nv0.4.0 optimizations: **22x** faster time travel, **5.6x** faster sync (hash/actor table caching),\n**13.5x** parallel read scaling (lock-free reads eliminate shared_mutex contention).\n\nSee [docs/benchmark-results.md](docs/benchmark-results.md) for full results, platform comparison,\nand perf analysis.\n\n## Design Philosophy\n\nInspired by Ben Deane's approach to modern C++:\n\n- **Make illegal states unrepresentable** — algebraic types model the domain precisely\n- **Algorithms over raw loops** — `std::ranges` pipelines, folds, transforms\n- **CRDTs are monoids** — merge is associative, commutative, and idempotent\n- **Strong types prevent mixups** — `ActorId`, `ObjId`, `ChangeHash` never interconvert\n- **Value semantics** — immutable outside transactions, explicit mutation boundaries\n\n## Building\n\n### Requirements\n\n- C++23 compiler (GCC 14+, Clang 18+, MSVC 19.38+)\n- CMake 3.28+\n- zlib (for raw DEFLATE compression)\n\n### Build\n\n```bash\ncmake -B build -DCMAKE_BUILD_TYPE=Release\ncmake --build build\n```\n\n### Build with tests, examples, and benchmarks\n\n```bash\ncmake -B build \\\n    -DCMAKE_BUILD_TYPE=Release \\\n    -DAUTOMERGE_CPP_BUILD_TESTS=ON \\\n    -DAUTOMERGE_CPP_BUILD_EXAMPLES=ON \\\n    -DAUTOMERGE_CPP_BUILD_BENCHMARKS=ON\n\ncmake --build build\nctest --test-dir build --output-on-failure\n```\n\n### Run benchmarks\n\n```bash\n./build/benchmarks/automerge_cpp_benchmarks\n```\n\n## Project Structure\n\n```\nautomerge-cpp/\n  include/automerge-cpp/     # public headers\n    automerge.hpp             #   umbrella header\n    document.hpp              #   Document class\n    transaction.hpp           #   Transaction class\n    types.hpp                 #   ActorId, ObjId, OpId, ChangeHash, Prop\n    value.hpp                 #   ScalarValue, Value, ObjType\n    change.hpp                #   Change struct\n    op.hpp                    #   Op, OpType\n    sync_state.hpp            #   SyncState, SyncMessage\n    patch.hpp                 #   Patch, PatchAction types\n    cursor.hpp                #   Cursor (stable position)\n    mark.hpp                  #   Mark (rich text annotation)\n    error.hpp                 #   Error, ErrorKind\n    thread_pool.hpp           #   BS::thread_pool (header-only)\n  src/                        # implementation\n    document.cpp              #   Document methods\n    transaction.cpp           #   Transaction methods\n    doc_state.hpp             #   internal: DocState, ObjectState\n    crypto/                   #   SHA-256 (vendored)\n    encoding/                 #   LEB128, RLE, delta, boolean codecs\n    storage/                  #   columnar binary format\n      columns/                #   column spec, op encoding, value encoding, compression\n    sync/                     #   bloom filter for sync protocol\n  tests/                      # unit and integration tests\n  examples/                   # example programs\n  benchmarks/                 # performance benchmarks\n  docs/                       # documentation\n    api.md                    #   API reference\n    style.md                  #   coding style guide\n    plans/                    #   architecture and roadmap\n  upstream/automerge/         # upstream Rust reference (git submodule)\n```\n\n## Examples\n\nSix example programs in `examples/`:\n\n| Example | Description |\n|---------|-------------|\n| `basic_usage` | Create doc, put/get values, counters, save/load |\n| `collaborative_todo` | Two actors concurrently editing a shared todo list |\n| `text_editor` | Text editing with patches, cursors, and time travel |\n| `sync_demo` | Peer-to-peer sync with SyncState |\n| `thread_safe_demo` | Multi-threaded concurrent reads and writes on a single Document |\n| `parallel_perf_demo` | Monoid-powered fork/merge parallelism, parallel save/load/sync |\n\n```bash\n./build/examples/basic_usage\n./build/examples/collaborative_todo\n./build/examples/text_editor\n./build/examples/sync_demo\n./build/examples/thread_safe_demo\n./build/examples/parallel_perf_demo\n```\n\n## Documentation\n\n- [API Reference](docs/api.md) — every public type, method, and usage examples\n- [Benchmark Results](docs/benchmark-results.md) — performance measurements\n- [Style Guide](docs/style.md) — coding style and conventions (Ben Deane's modern C++ principles)\n- [Architecture Plan](docs/plans/architecture.md) — design principles, core types, module layout\n- [Implementation Roadmap](docs/plans/roadmap.md) — phased development plan with status\n\n## License\n\nMIT License. See [LICENSE](LICENSE).\n\n## Acknowledgments\n\n- [Automerge](https://automerge.org/) — the original CRDT library by Martin Kleppmann et al.\n- [automerge-rs](https://github.com/automerge/automerge) — the upstream Rust implementation\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhomer6%2Fautomerge-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhomer6%2Fautomerge-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhomer6%2Fautomerge-cpp/lists"}