Skip to content

Conversation

@tim-one
Copy link
Member

@tim-one tim-one commented May 24, 2024

Make it impossible for Differ.compare() to degenerate to cubic-time. This may change results in some cases, but no natural ones come to mind, and I don't care about contrived cases.

tim-one added 4 commits May 23, 2024 18:22
…window of 10 lines, and picks "the first" pair within the current window with a ratio > cutoff to synch on. This should make cubic-time cases impossible. It may change results in some cases, but I don't think I care - difflib is fundamentally opposed to synching on lines "far apart", and using a window enforces a notion of locality.
@tim-one tim-one linked an issue May 24, 2024 that may be closed by this pull request
@tim-one tim-one merged commit de19694 into python:main May 25, 2024
@tim-one tim-one deleted the differ branch May 25, 2024 03:08
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
…ython#119492)

``_fancy_replace()`` is no longer recursive. and a single call does a worst-case linear number of ratio() computations instead of quadratic. This renders toothless a universe of pathological cases. Some inputs may produce different output, but that's rare, and I didn't find a case where the final diff appeared to be of materially worse quality. To the contrary, by refusing to even consider synching on lines "far apart", there was more easy-to-digest locality in the output.
adacore-bot pushed a commit to AdaCore/e3-aws that referenced this pull request Dec 11, 2025
From python/cpython#119492, "This may change
results in some cases, but no natural ones come to mind, and I don't
care about contrived cases." and also "Correctness of diffs is not
affected. Some similar lines far apart may be reported as deleting
one and adding the other, where before they were displayed on adjacent
output lines with markup showing the intraline differences.".

This change breaks the test for Python3.14
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.

difflib.py Differ.compare is too slow [for degenerate cases]

1 participant