Skip to content

Refactor LiveText to use diff-match-patch#11500

Closed
codeofdusk wants to merge 12 commits into
nvaccess:masterfrom
codeofdusk:livetext-dmp
Closed

Refactor LiveText to use diff-match-patch#11500
codeofdusk wants to merge 12 commits into
nvaccess:masterfrom
codeofdusk:livetext-dmp

Conversation

@codeofdusk

@codeofdusk codeofdusk commented Aug 16, 2020

Copy link
Copy Markdown
Contributor

Link to issue number:

Closes #3200. Closes #11498.

Summary of the issue:

LiveText objects use difflib to calculate text changes:

  • Difflib is slow, making 10,000-line objects completely unusable and slowing down or locking up NVDA for other large objects.
  • Comparisons are made at the line level, so edits in the middle of lines cause characters to the right of the caret to be read out.
  • In 21H1 UIA console, when a large amount of text is written, the diff lags far behind the actual console's output, making autoread unusable until NVDA or the console is restarted.

Description of how this pull request fixes the issue:

This PR replaces difflib with diff-match-patch (DMP) for LiveText objects, and changes diffing functions to operate at the string rather than line level.

Testing performed:

Known issues with pull request:

  • While this PR really helps in many extreme cases, there are others where it is actually slower than difflib by about half a second. I propose a follow-up PR to switch to the C++ version, either implemented as a Python extension or as part of NVDAHelper. Initial testing suggests that the C++ library is much faster in these cases.
  • Since this PR alone represents a fairly major change, I'd like to get it into 2020.4 fairly early (to get lots of testing time in on master).

Change log entry:

== Bug Fixes ==

== Changes For Developers ==

@codeofdusk

Copy link
Copy Markdown
Contributor Author

Cc @camlorn @feerrenrut @jcsteh @LeonarddeR @michaelDCurran.

@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit adb46d31a7

Comment thread source/NVDAObjects/window/winConsole.py Outdated
Comment thread source/winConsoleHandler.py Outdated
@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 8314eab57d

@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit fb60d6866e

@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 9b3803405f

@codeofdusk codeofdusk marked this pull request as draft August 17, 2020 07:19

@LeonarddeR LeonarddeR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Make sure to update the dependencies seciton of the readme

Comment thread source/NVDAObjects/behaviors.py Outdated
Comment thread source/NVDAObjects/behaviors.py Outdated
@ahicks92

Copy link
Copy Markdown
Contributor

Don't have much to comment on here, but glad to know this might get improved in a meaningful fashion. It'd be nice if using nano wasn't very painful, as it is today.

I'll make a point of testing once this lands.

@LeonarddeR

Copy link
Copy Markdown
Collaborator

@codeofdusk there have been several changes in this pr. Does the description still match the current situation of the code?

@codeofdusk

Copy link
Copy Markdown
Contributor Author

Yes – I've been keeping the description up-to-date as I've made changes.

This should make it compatible with NVDA, otherwise Espeak wouldn't be and it's a fairly major component (it's under GPL3 and has a similar patent clause).
@codeofdusk

Copy link
Copy Markdown
Contributor Author

I'm closing the PR in its current form due to licence incompatibility. I'll open a new one that calls DMP in a separate process to avoid linking with NVDA.

feerrenrut added a commit that referenced this pull request Dec 31, 2020
Refactor LiveText to use diff-match-patch via IPC with another process

Changes diffing functions to operate at the string rather than line level.
Adds diff-match-patch (DMP) as an optional diffing algorithm for LiveText objects.
It is anticipated that DMP will become the default in a future NVDA release pending positive user testing.

Unlike #11500, this PR does not import or dynamically link to DMP due to licensing issues.
Instead, a Python application is run in another process that calls the DMP extension, and communicates over standard IO.

Co-authored-by: Michael Curran <michaelDCurran@users.noreply.github.com>
Co-authored-by: Reef Turner <feerrenrut@users.noreply.github.com>
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.

LiveText: consider using diff-match-patch better support for editing characters in the middle of lines in command prompt/terminal

6 participants