Skip to content

core: text line diff, unified output and bench-diff - #668

Merged
foxnne merged 2 commits into
mainfrom
core/diff-text-qeubdv
Oct 19, 2026
Merged

foxnne merged 2 commits into
mainfrom
core/diff-text-qeubdv

Conversation

@foxnne

@foxnne foxnne commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Part of fizzyedit/plans plans/DIFF_PLAN.md step 1 (2.1-2.2, 3).

What

Std-only core.diff (core/diff.zig, core/diff/{Text,unified,tests}.zig):

  • Text: reusable scratch; byte prefix/suffix trim with @Vector(32, u8), line interning (Wyhash, byte-exact on match), histogram diff (occurrence cap 64) with an explicit stack, Myers (linear space, max_cost cap, then the range is replaced) when there is no anchor, hunk sliding to blank-line/low-indent boundaries. Hunks carry lines and bytes; Text.edit gives a byte-range Edit; Text.range converts to protocol positions through the owner's byte-to-position callback.
  • unified.write: standard @@ -a,l +b,l @@ with context, \ No newline at end of file, and a max_bytes cap that drops whole trailing hunk groups and says ... N more hunks.
  • bench-diff + tests (round trip over random edits on text/CRLF/no final newline/binary, scratch reuse allocates nothing, unified fixtures and cap), wired into build/app.zig.

Not in this step (named seams): budget_ns partial/resume, word/char refinement and merge (step 2), cmdWrite untouched.

Bench (zig build bench-diff -Doptimize=ReleaseFast, 1.15 MB / 25k lines, Linux)

Case Time Budget
identical 0.10 ms 0.2
one line inserted 0.07 ms 2
1% scattered (250 hunks) 13.2 ms 15
every line changed 1.7 ms 60
two-line alphabet (Myers, capped) 16.3 ms 60

Prior-art notes in the plan (git histogram, JGit, imara-diff) were not re-fetched; the implementation follows git's histogram scoring from memory and diff-match-patch's bisect for Myers.

Verified

scripts/check-fmt.sh, zig build test, check-web, check-tests-reached pass. No SDK boundary change.


Generated by Claude Code

…bench-diff

Part of fizzyedit/plans DIFF_PLAN step 1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011eSdUZNiSkni93mqVrUxy7
@foxnne
foxnne marked this pull request as ready for review October 19, 2026 20:35
@foxnne
foxnne added this pull request to the merge queue Oct 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 19, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011eSdUZNiSkni93mqVrUxy7
@foxnne
foxnne added this pull request to the merge queue Oct 19, 2026
Merged via the queue into main with commit 6a52622 Oct 19, 2026
11 checks passed
@foxnne
foxnne deleted the core/diff-text-qeubdv branch October 19, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants