Skip to content
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

Renders the HTML from the Markdown source in a separate thread, fixin… #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sergiodlc
Copy link

What changes:

  1. There's an UpdateThread class that inherits from threading.Thread to run the conversion between the markdown source into the HTML for the live preview in a separate thread. An instance of this class is owned by the main window and is started when the window shows. The update thread runs in parallel for the duration of the program, sleeping while there's no rendering requests.
  2. The update_live_preview() method now sets up a GLib timer that notifies the update thread that a new update to the live preview is needed. If this method is called again before the timer has fired, it resets the timer, effectively cancelling the previous update request. The end result is that while the user is typing in rapid succession, updates to the live preview are postponed, avoiding rendering in bursts. The timer delay is set to 200 ms, a sensible value according to my tests.

It is worth mentioning that, unlike the markdown to HTML rendering, the actual update to GTK widgets (i.e. setting the HTML in the Webkit widget and recalculating the scrolling) are enqueued as low priority tasks in the main thread, since GTK is not thread safe (See Threads/Concurrency with Python and the GNOME Platform).

These changes mostly fix Issue #13 (see extreme cases below).

Tests

I tested these changes in Arch Linux (python-gobject 3.22). I compared the behavior of Remarkable with and without these changes, with small files (~ 1000 characters, a few paragraphs), medium files (15,000 characters, about the length of a blog post), large files ( 100,000 characters, about the length of a small book like The Little Prince) and very large files (~ 4M characters, the size of the Bible). For small and medium files, the only perceived change is that the delay rendering logic doesn't update the live preview as often as before. Without the changes, large files couldn't be edited with Remarkable with the live preview on, as every time you typed a character the editor would become unresponsive for about a second or two. With the changes they are editable with the live preview on with no perceived issues.

Now, very large files (I used the King James Bible) are still largely unable to be handled with the live preview on. The responsiveness is greatly improved in those cases, though. We need more testing for these extreme cases to zero in the bottlenecks.

…g lag in the text window while typing, specially on large documents. Adds a 200 ms delay between the text change event and the start of the rendering process to avoid triggering rendering requests in bursts while typing. Fixes issue jamiemcg#13.
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.

1 participant