# @vscode/diff

> A high-performance diff algorithm implementation with WASM backend, ported from VS Code

Latest version **0.0.2-0** (published 2026-05-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @vscode/diff
pnpm add @vscode/diff
yarn add @vscode/diff
bun add @vscode/diff
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.2-0 |
| Published | 2026-05-14 |
| First published | 2026-05-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 428 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Microsoft Corporation |
| Maintainers | vscode-bot, microsoft1es |
| Keywords | diff, lcs, vscode, wasm, rust |

## Links

- npm: https://www.npmjs.com/package/@vscode/diff
- Repository: https://github.com/microsoft/vscode-packages
- Homepage: https://github.com/microsoft/vscode-packages/tree/main/vscode-diff
- Issues: https://github.com/microsoft/vscode-packages/issues
- npm.io page: https://npm.io/package/@vscode/diff

## Recent versions

- 0.0.2-0 (latest) — 2026-05-14
- 0.0.2-52 (next) — 2026-09-18
- 0.0.2-51 — 2026-09-18
- 0.0.2-50 — 2026-09-16
- 0.0.2-49 — 2026-09-11
- 0.0.2-48 — 2026-09-10
- 0.0.2-47 — 2026-09-10
- 0.0.2-46 — 2026-09-08
- 0.0.2-45 — 2026-08-31
- 0.0.2-44 — 2026-08-24
- 0.0.2-43 — 2026-08-12
- 0.0.2-42 — 2026-08-05
- 0.0.2-41 — 2026-07-29
- 0.0.2-40 — 2026-07-28
- 0.0.2-39 — 2026-07-27
- … 38 more at https://npm.io/package/@vscode/diff/versions

## README

# @vscode/diff

> ⚠️ **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:

- **TypeScript** (default) — pure JS, no native dependencies.
- **WebAssembly** — same algorithm compiled from Rust via `wasm-pack`. Typically ~1.5–3× faster on larger inputs.

Both produce identical results.

## Install

```sh
npm install @vscode/diff
```

## Usage

```ts
import { 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`](./src/diff/api/types.ts) 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`.

### Options

| 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. |

## Performance

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.

## License

MIT — see [LICENSE](./LICENSE).

---
_Source: https://npm.io/package/@vscode/diff · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
