{"id":15038575,"url":"https://github.com/heckj/crdt","last_synced_at":"2025-04-05T01:06:28.681Z","repository":{"id":63920301,"uuid":"527051666","full_name":"heckj/CRDT","owner":"heckj","description":"Conflict-free Replicated Data Types in Swift","archived":false,"fork":false,"pushed_at":"2024-12-10T17:17:06.000Z","size":17939,"stargazers_count":168,"open_issues_count":4,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-05T01:06:13.700Z","etag":null,"topics":["crdt","crdt-implementations","crdts","swift"],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/heckj/CRDT/main/documentation/crdt","language":"Swift","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/heckj.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}},"created_at":"2022-08-20T22:18:36.000Z","updated_at":"2025-03-26T02:08:07.000Z","dependencies_parsed_at":"2024-01-17T21:50:37.765Z","dependency_job_id":"c3a7d97a-900d-4c9b-a024-f299b9735c39","html_url":"https://github.com/heckj/CRDT","commit_stats":{"total_commits":135,"total_committers":3,"mean_commits":45.0,"dds":"0.014814814814814836","last_synced_commit":"f3616e1fbd9665ca0b2d2fbea290bd3abdb18dd5"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heckj%2FCRDT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heckj%2FCRDT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heckj%2FCRDT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heckj%2FCRDT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heckj","download_url":"https://codeload.github.com/heckj/CRDT/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271530,"owners_count":20911587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["crdt","crdt-implementations","crdts","swift"],"created_at":"2024-09-24T20:39:01.615Z","updated_at":"2025-04-05T01:06:28.658Z","avatar_url":"https://github.com/heckj.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CRDT\n\nAn implementation of ∂-state based Conflict-free Replicated Data Types (CRDT) in the Swift language.\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fheckj%2FCRDT%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/heckj/CRDT)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fheckj%2FCRDT%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/heckj/CRDT)\n[![codecov](https://codecov.io/gh/heckj/CRDT/branch/main/graph/badge.svg?token=AP68RBHNHM)](https://codecov.io/gh/heckj/CRDT)\n\n[![code coverage chart](https://codecov.io/gh/heckj/CRDT/branch/main/graphs/sunburst.svg?token=AP68RBHNHM)](https://codecov.io/gh/heckj/CRDT)\n\n## Overview\n\nThis library implements well-known state-based CRDTs as swift generics, sometimes described as convergent replicated data types (CvRDT).\nThe implementation includes delta-state replication functions, which allows for more compact representations when syncing between collaboration endpoints. The alternative is to replicate the entire state for every sync.\n\nThe [CRDT API documentation](https://swiftpackageindex.com/heckj/CRDT/main/documentation/crdt) is hosted at the [Swift Package Index](https://swiftpackageindex.com/).\n\n- [X] G-Counter (grow-only counter)\n- [X] PN-Counter (A positive-negative counter)\n- [X] LWW-Register (last write wins register)\n- [X] G-Set (grow-only set)\n- [X] OR-Set (observed-remove set, with LWW add bias)\n- [X] OR-Map (observed-remove map, with LWW add or update bias)\n- [X] List (causal-tree list)\n\nFor more information on CRDTs, the [Wikipedia page on CRDTs](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type) is quite good.\nI'd also suggest the website [CRDT.tech](https://crdt.tech) as a wonderful collection of further resources.\nThe implementations within this library were heavily based on algorithms described in\n[Conflict-free Replicated Data Types](https://arxiv.org/pdf/1805.06358.pdf) by Nuno Preguiça, Carlos Baquero, and Marc Shapiro (2018), and heavily influenced/sourced from the package [ReplicatingTypes](https://github.com/appdecentral/replicatingtypes), created by [Drew McCormack](https://twitter.com/drewmccormack), used under license (MIT).\n\n### What's Different about this Package\n\nThe two most notable change from Drew's code are:\n- consistently exposing the type used to identify the collaboration instance (be that person, process, or machine) as a generic type\n- adding explicit delta-state transfer mechanisms so that you didn't need to transfer the entirety of a CRDT instance to another location in order to merge the data.\n\nLike the [ReplicatingTypes](https://github.com/appdecentral/replicatingtypes) package, this package is available under the MIT license for you to use as you like, asking only for recognition that it was sourced.\n\nIf your goal is creating [local-first software](https://www.inkandswitch.com/local-first/), this implementation is start, but (in my opinion) incomplete to those needs.\nIn particular, there are none of the serialization optimizations included that would reduce the space needed by the instances when serialized in their entirety to be stored.\nThere are also none of the optimizations that other libraries (for example [Automerge](https://automerge.org) or [Yjs](https://yjs.dev)) that improve memory overhead needed to support longer-form collaborative text interactions.\n\nThese limitations may change in the future, and contributions are welcome.\n\n## Alternative Packages and Libraries\n\nOther Swift implementations of CRDTs:\n- https://github.com/appdecentral/replicatingtypes\n    - related article: [Conflict-Free Replicated Data Types (CRDTs) in Swift](https://appdecentral.com/2020/07/12/conflict-free-replicated-data-types-crdts-in-swift/)\n- https://github.com/bluk/CRDT\n- https://github.com/jamztang/CRDT\n- https://github.com/archagon/crdt-playground\n  - related article: [Data Laced with History: Causal Trees \u0026 Operational CRDTs](http://archagon.net/blog/2018/03/24/data-laced-with-history/)\n- Objc.io video series: [CRDTs – Introduction](https://talk.objc.io/episodes/S01E294-crdts-introduction)\n\nTwo very well established CRDT libraries used for collaborative text editing:\n- [Automerge](https://automerge.org)\n  - (video) [CRDTs: The Hard Parts](https://youtu.be/x7drE24geUw) by [Martin Kleppmann](https://martin.kleppmann.com/2020/07/06/crdt-hard-parts-hydra.html))\n- [Y.js](https://yjs.dev) (and its multi-language port [Y-CRDT](https://github.com/y-crdt))\n  - Yrs data structure internals: https://bartoszsypytkowski.com/yrs-architecture/\n\n### Optimizations\n\nArticles discussing tradeoffs, algorithm details, and performance, specifically for sequence based CRDTs:\n- [Delta-state CRDTs: indexed sequences with YATA](https://bartoszsypytkowski.com/yata/)\n- [5000x faster CRDTs: An Adventure in Optimization](https://josephg.com/blog/crdts-go-brrr/)\n- [CRDTs: The Hard Parts](https://martin.kleppmann.com/2020/07/06/crdt-hard-parts-hydra.html)\n  - [CRDTs: The Hard Parts video](https://youtu.be/x7drE24geUw)\n\n## Benchmarks\n\nRunning the library:\n\n    swift run -c release crdt-benchmark library run Benchmarks/results.json --library Benchmarks/Library.json --cycles 5 --mode replace-all\n    swift run -c release crdt-benchmark library render Benchmarks/results.json --library Benchmarks/Library.json --output Benchmarks\n\n[Current Benchmarks](./Benchmarks/Results.md)\n\nThere's also stubbed benchmarks using package-benchmark under the ExternalBenchmarks directory.\nThese additional benchmarks are primarily one-dimensional and DO require that additional libraries are\ninstalled (jemalloc) in order for them to operate. If you just want to explore, the .devContainer\nsetting in this repository includes that library - so it's easy to trial this out from within\nVSCode and Docker. To explore the 1-dimension external benchmarks:\n\n```bash\ncd ExternalBenchmarks\nswift package benchmark\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheckj%2Fcrdt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheckj%2Fcrdt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheckj%2Fcrdt/lists"}