Myers diff slows to quadratic on large agent rewrites, so one post uses edit spans to speed it up

_jzhao · x · 2026-07-22

A mini blog post explains why Myers’ default unified-diff algorithm degenerates on large edits, and how a strreplace-like tool can use edit spans to speed diff computation by orders of magnitude.

The post includes a visual explanation of the edit graph, showing how the search band widens as matches disappear in large rewrite cases. The author argues that agent workflows often produce the opposite workload from normal human editing: tools may rewrite thousands of lines at once, causing Myers to approach quadratic behavior. In one real case, a single degenerate diff took 4.3 seconds and stalled the whole agent.

Original post →

More from coding & agent

coding & agent channel →