Operations and Changes
Quick Reference
Operations are atomic edits. Changes are logical groups of operations with metadata. Understanding these helps optimize sync and performance.
Key Concepts
Operations
- Atomic units of change (insert a single Unicode character, delete a single character, insert an new entry to a map, etc.)
- Automatically merged internally for efficiency
- Each has unique ID:
(peerId, counter)
Changes
- Groups of consecutive operations
- Include metadata (timestamp, dependencies, peer ID)
- Created by
commit()
or auto-commit
const = new ();
const = .("text");
.(0, "Hello"); // Operation
.(5, " World"); // Operation
.(); // Groups into one Change
Automatic Merging
Consecutive operations from same peer merge into one Change:
const = new ();
const = .("text");
.(0, "abc");
.(); // Change #1
.(3, "def");
.(); // Merges with #1 (same peer, consecutive)
When New Changes Are Created
- Cross-peer dependencies: After importing remote operations
- Time separation: When timestamps enabled and > the merge interval (default 1000s) between commits
- Different commit messages:
const = new ();
.("text").(0, "v1");
.(); // Change #1
// Import from another peer
const = new ();
.("text").(0, "v1");
const = .({ : "update" });
.();
// Next commit creates new Change (dependency on remote)
.("text").(0, "v2");
.(); // Change #2
Impact on Sync & Storage
- History: Changes track logical units of work
- Sync: Dependencies ensure causal ordering
- Storage: Auto-merging reduces metadata overhead
Related Documentation
- Transaction Model - Grouping operations
- Version Vector - How Changes form versions
- Synchronization - Using Changes for sync