p+pathadd.comTools / Everyday tools

TEXT / CHANGE / EVIDENCE

Text comparison

Local comparison · No uploads

Left · Original

Right · Revised

1 / 2
− Left: removed / original+ Right: added / revised

ENGINEERING PRESSURES / ALGORITHMS / SEMANTICS

Why comparing changes helps

01 / Review the changes, not two whole files

Configuration deployments, messages and code reviews often involve mostly unchanged content. Reading two entire files can miss a port, a negation or a permission line. A comparison focuses attention on additions, removals and nearby context. It reduces repeated reading but does not decide whether a change is correct.

Unix diff made text differences a representation that could be saved and exchanged, later used by patches and version control. Lines are useful units for source and configuration. A message or minified JSON on one long line may need character-level or structural comparison; line comparison cannot infer field meaning.

Original and revised values appear side by side. A replacement counts as removed original lines and added revised lines. Adjacent changes are aligned by order for readability, not guaranteed semantic correspondence. Repeated lines and moved code can permit several shortest paths. A diff is one account of the changes, not the unique editing history.

02 / Small edit scripts still need computation limits

Difference algorithms often seek common subsequences or short edit scripts: which units stay, and which are inserted or removed. Myers' 1986 O(ND) algorithm relates work to sequence size and edit distance, fitting many mostly similar texts. Completely different, highly repetitive or very long inputs can still be expensive.

This page runs the established jsdiff engine in a Worker with input, edit-distance and time limits. If it cannot finish within budget, it reports that rather than partial results. Inline highlighting uses extended grapheme clusters to avoid splitting combining accents and emoji. Very long or complex lines retain their original text with line-level differences only.

Inline highlights show original character differences in aligned lines. Ignore rules affect line matching and addition/removal counts. Grapheme clusters approximate perceived characters, not glyphs or semantic units. Visually similar Unicode characters may differ. No case folding, normalization or automatic formatting is performed.

03 / Equal text, equal bytes and equal meaning differ

The same text can have different bytes in UTF-8 and GBK; different JSON text can represent the same object. Indentation can be presentation in one format and meaningful in Python or YAML. Whether SQL whitespace is ignorable depends on its position. Equality after ignoring whitespace does not establish equal program behavior.

CRLF versus LF, a final newline and a leading BOM can affect hashes, scripts and protocols. These differences are preserved by default. Ignore rules must be enabled explicitly; equality under those rules still reports whether originals differ. Space ignoring covers ASCII spaces and Tabs only, not blank lines, nonbreaking spaces or other Unicode characters.

File import retains the UTF-8 BOM and original newline characters in memory without rewriting the file. Textareas use LF according to browser behavior; once you edit, the edited text becomes authoritative. Swapping and downloads use complete in-memory originals. If source encoding is uncertain, first use Text encoding to check it rather than comparing garbled text as if it were correct.

Deployment review: differences are evidence, not verdicts

Establish each side's source, version and encoding before choosing comparison rules. Review context as well as changed lines: the same setting in another scope can mean something different. A newline can matter to signed bytes; a single digit can be critical in a port or amount.

Only text is compared. JSON/XML/SQL semantics are not parsed, scripts are not executed, and merging or patch application is not provided. Files require strict UTF-8; convert other encodings explicitly first. Each side allows 256 KiB files, 65536 UTF-16 code units and 2000 lines. Difference size or time limits can stop a calculation early.

Comparison JSON contains complete left and right lines, line numbers, endings, rules and highlights. It is not an applicable patch. Input is not uploaded or saved; only site preferences are stored. Downloads may contain credentials, configuration or personal information and need the same care as the originals.

References: GNU Diffutils · Myers · An O(ND) Difference Algorithm and Its Variations · jsdiff · Unicode text segmentation