Skip to content

Conversation

@krassowski
Copy link
Collaborator

@krassowski krassowski commented Nov 29, 2025

@krassowski krassowski added the enhancement New feature or request label Nov 29, 2025
@krassowski krassowski marked this pull request as ready for review November 29, 2025 10:20

# for very different strings, just replace the whole content;
# this avoids generating a huge number of operations
if matcher.ratio() < 0.6:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 0.6 because:

As a rule of thumb, a ratio() value over 0.6 means the sequences are close matches

As per https://docs.python.org/3/library/difflib.html#sequencematcher-examples

Instead of ratio() we could use quick_ratio() or real_quick_ratio(). In case if the ratio is above the threshold this does not matter because we would end up computing matching_blocks anyways (this is computed and cached by a call to either raito() or get_opcodes(); in that case calling quick_ratio heuristic could actually end up taking more time as we end up doing more work. It all boils down to whether we think that we are more likely to see smaller updates or larger updates. One very cheap heuristic could be using len of both strings which is what real_quick_ratio does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not reload text document if text was apened out-of-band?

1 participant