Launching today

Treediff
AST code diff engine in Rust with move & rename detection
2 followers
AST code diff engine in Rust with move & rename detection
2 followers
Treediff is an open-source (Apache-2.0) structural code diff engine in Rust powered by 17 Tree-sitter grammars. It uses an arena CST, dual exact/alpha Merkle hashing, and O(N log N) monolith alignment to detect moved functions, renamed symbols, and cross-file relocations—even in files with syntax errors. Every diff emits a byte-for-byte verified edit script, JSON v1.0 output, Git external diff integration, and C/Python FFI bindings.




Free
Launch Team

AWS Startup AdvisorPersonalized AWS guidance that meets you where you’re already building
Promoted
Hey Product Hunt — I built Treediff, an open-source (Apache-2.0) structural code diff engine written in Rust.
Why build another diff tool?
Traditional line diffs break on moved functions and renamed variables. Existing structural tools either skip move/rename tracking (Difftastic), fall back to plain line diffs on syntax errors or large files (Diffmantic's default 10k-line limit), or carry JVM startup and pointer-heavy AST overhead (GumTree).
How Treediff works:
Arena CST + Dual Merkle Hashing: Contiguous Vec<AstNode> with 32-bit indices, a single-buffer string interner, exact_hash, alpha-renamed alpha_hash (structure modulo identifiers/literals), and a 64-bit sim_sketch.
5-Phase Hybrid Matching: O(N) prefix/suffix pruning, height-ordered lazy Merkle top-down matching, context-scored duplicate disambiguation, O(K log K) LIS move detection across files/classes/modules, and O(N log N) hash-anchored alignment for large monoliths.
Error-Tolerant Recovery: Multi-line Tree-sitter ERROR spans are recovered into structured subtrees so broken files stay structurally comparable.
Verified Lossless Reconstruction: Every diff emits non-overlapping TextEdit operations verified byte-for-byte (apply(old, edits) == new).
17 Native Languages + Fallback: Rust, Python, JS, TS, TSX, Go, C, C++, Java, JSON, TOML, YAML, HTML, CSS, Bash, Ruby, Zig, plus a balanced-delimiter fallback parser.
Measured Benchmarks (Windows 10 x86_64, AMD PRO A12-9800B, 8 GB RAM):
ripgrep/standard.rs (282 KB): 256.5 ms / 26.3 MB vs. Diffsitter 0.9.0 (583.0 ms / 50.9 MB), Diffmantic 0.18.0 (842.9 ms / 53.5 MB), Difftastic 0.72.0 (1450.0 ms / 45.8 MB), GumTree 4.1.0 (TIMEOUT 30.7s / 240.9 MB).
5,000 Rust functions (673 KB): 588.3 ms / 90.2 MB (with moves=1, renames=1) vs. Diffsitter (1208.6 ms / 167.8 MB), Difftastic (3238.5 ms / 164.4 MB), Diffmantic (7367.7 ms / 364.2 MB).
Honest trade-offs: On tiny <1 KB files, Diffsitter is faster in 3 of 5 cases because it runs leaf-only LCS without move/rename analysis, though Treediff keeps the lowest peak memory (~7.1 MB). At 12,000 functions, Diffmantic finishes in 259 ms only because its default --line-limit 10000 falls back to text line diffing, whereas Treediff completes full AST + move + rename analysis in 1.32s.
Source & prebuilt binaries (Linux, macOS, Windows): github.com/A35-777/treediff · Live interactive explorer & full benchmark table: treediff.pages.dev. Feedback on edge-case grammars and benchmarks is very welcome!