You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
difflib.HtmlDiff has quadratic line pairing for lopsided replacements #156505
difflib._mdiff() buffers unmatched lines in lists and consumes them using pop(0). For lopsided replacement blocks, each removal shifts the remaining
items, making line pairing quadratic.
The speedup increases with input size, reaching 7.94x at 128,000 lines. Patched
runtime scales approximately linearly.
Using collections.deque for the two pairing queues preserves FIFO behavior
while making removal constant-time. Focused tests, the complete test_difflib
suite, and randomized differential testing confirm identical output.
Activity
gh-156505: Speed up difflib.HtmlDiff for lopsided replacements (GH-15…
encukou commentedon Sep 7, 2026
Thank you for the fix!
pythongh-156505: Speed up difflib.HtmlDiff for lopsided replacements (p…