-
Notifications
You must be signed in to change notification settings - Fork 920
Chore: improve getDiff perfomance for the editor #2517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This PR is ready to be tested for anyone. Please, if you detect that something is not working, report it here. |
Please provide them with minimal steps to test your branch: dependency_overrides:
flutter_quill:
git:
url: https://github.com/CatHood0/flutter-quill.git
ref: improve_diff BTW, I remember you telling this doesn't make a performance different. is it different now? |
Yes, that was because it only improved the previous implementation, but didn't change its foundation. The problem with the previous one is that it didn't limit the ranges for searching for changes. That is, with the previous Unlike that, the new By limiting the range, performance improves significantly, since it doesn't have to loop all the way to the end. Of course, always keep in mind that all this is relative to the cursor position. Here is where we compute the exact ranges that we will process: TextRange _getAffectedRange(
String oldStr,
String newStr,
TextSelection oldSel,
TextSelection newSel,
) {
// Calculate combined selection area
final start = math.min(oldSel.start, newSel.start);
final end = math.max(oldSel.end, newSel.end);
// Expand by 20% to capture nearby changes
//
// We use this to avoid check all the string length
// unnecessarily when we can use the selection as a base
// to know where, and how was do it the change
final expansion = ((end - start) * 0.2).round();
return TextRange(
start: math.max(0, start - expansion),
end: math.min(math.max(oldStr.length, newStr.length), end + expansion),
);
} |
This comment was marked as resolved.
This comment was marked as resolved.
I'm trying to record the video well so that it works better, but also so that it doesn't look so laggy, because, due to external factors (node rendering), no matter how much I improve For some quick context, remember that when there are new lines in the text, the nodes are split, and this means, there are more paragraphs, and there are more nodes. That means: more to render and we don't check which nodes are visible and which are not (which causes this), so, we are rendering all at the same time. |
@EchoEllet probably comparing characters by index is too heavy? And it would actually explain why I'm unable to demonstrate the power of this PR in the videos. I previously tried adding 50,000 words into the editor and it worked just fine (literally as you'd expect from an editor), but adding the code that (ironically) I removed in the video significantly degrades the performance. clideo_editor_d41a1d16217a41b797f3cf36e2a4c586.mp4 |
This comment was marked as outdated.
This comment was marked as outdated.
Since #2510 is working on avoid use of |
Description
Improved the performance of the
getDiff
method, which calculates the differences between two texts (oldText
andnewText
). The main focus is to optimize the code to handle extremely long strings (e.g., 24,000 words or more) without affecting the editor's responsiveness.Note
The videos for preview how this PR will be added as soon as i can fix a little part of code that degrades the perfomance.
Related Issues
Type of Change