deltamesh

Introduction

deltamesh answers one question: given two large structured documents, what is the smallest set of operations that turns the first into the second — and can we compute it without loading either into memory?

When you want this

When you do not

If your documents comfortably fit in memory and you already emit change events at the source, a plain JSON Patch library will be simpler and faster. deltamesh earns its complexity from about 50 MB per document upwards.

Compatibility. Patches serialise to RFC 6902 JSON Patch when the document is JSON and no binary values are present, so downstream consumers do not need deltamesh to apply them.

Model

Internally every input is projected onto the same tree: ordered sequences, unordered maps with comparable keys, and opaque leaves. The differ walks both trees in lockstep, emitting operations as soon as a subtree is known to differ — which is what keeps memory flat.

// the four operation kinds
type Op struct {
    Kind  OpKind  // Insert | Delete | Replace | Move
    Path  Path    // location in the target tree
    Value Value   // nil for Delete
}

Guarantees

PropertyHoldsNotes
DeterminismYesSame inputs produce byte-identical patches
MinimalityPer subtreeGlobally minimal edit scripts are NP-hard for unordered trees
ReversibilityYesUnless WithCompactDeletes is enabled
StreamingYesBoth differ and applier

Next

Head to the quickstart for a working example in about ten lines.