package
A high-performance diff algorithm implementation with WASM backend, ported from VS Code
npm install @vscode/diffGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
428.0 kB
Includes dependencies.
microsoft1es
npmjs@microsoft.com
⚠️ Experimental — this package is in early development. The API may change without notice and bugs are expected. Do not depend on it for production workloads yet.
A high-performance diff library, ported from the diff algorithm used inside VS Code. Ships with two interchangeable backends:
wasm-pack. Typically ~1.5–3× faster on larger inputs.Both produce identical results.
npm install @vscode/diffimport { createDiffComputer } from '@vscode/diff';
// TS backend (synchronous-feeling, no init required)
const ts = await createDiffComputer();
const result = ts.computeDiff(original, modified, {
ignoreTrimWhitespace: false,
computeMoves: false,
});
// WASM backend (loads the .wasm module on first call)
const wasm = await createDiffComputer({ useWasm: true });
const result2 = wasm.computeDiff(original, modified);computeDiff returns a DiffResult containing:
edits — an AnnotatedStringEdit describing the text-level changes (offset-based, suitable for applying directly).moves — detected block moves (when computeMoves: true).hitTimeout — true if computation exceeded maxComputationTimeMs.| Option | Default | Description |
|---|---|---|
maxComputationTimeMs | 0 (no limit) | Cap the diff time; falls back to a coarser result on timeout. |
ignoreTrimWhitespace | false | Treat lines as equal when they differ only in leading/trailing whitespace. |
computeMoves | false | Detect moved blocks. |
extendToSubwords | false | Refine inner changes to subword boundaries. |
Across all bundled test fixtures (46 cases, total median time in ms):
| Backend | Total | vs TS | vs native Rust |
|---|---|---|---|
| TS (V8) | 113.7 | 1.00× | 2.86× slower |
| WASM | 72.5 | 0.64× | 1.82× slower |
| Native Rust (reference) | 39.8 | 0.35× | 1.00× |
Run node scripts/bench.mjs to reproduce.
MIT — see LICENSE.