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

Performance fixes #75

Merged
merged 8 commits into from
Apr 27, 2020
Merged

Performance fixes #75

merged 8 commits into from
Apr 27, 2020

Conversation

sbrudz
Copy link
Contributor

@sbrudz sbrudz commented Apr 24, 2020

This PR addresses performance issues with Just Not Sorry on long emails.

In version 1.6.2 (and earlier), a long email with many just's and sorry's will slow typing performance to a crawl. As noted in #65 this is because on each keystroke, the code is removing and re-adding all of the warnings. This causes layout thrashing and greatly reduces performance as the browser tries to catch up.

This PR makes the following changes to improve performance:

  • Reduce the frequency of calls to recalculate warnings by using a debounce function to only trigger the recalculation 0.5 seconds after typing stops.
  • Batch DOM measurements and mutations to reduce layout thrashing using the fastdom library
  • Eliminate extraneous input events by tightening up the mutation observer logic

It also adds more test coverage for the mutation observer-related code.

Fixes #65

element.textContent = 'Hello';
target.appendChild(element);

setTimeout(function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

These nested timeouts look like they must have been a pain to work with, but the tests all pass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They were definitely a pain. I tried using jasmine's mock clock instead, but it didn't work. From what I could tell from stack overflow posts, jasmine doesn't mock out enough to be able to trigger the mutation observers. setTimeout was the best I could do. I'm open to suggestions for better ways to do it. I'm also hoping that if we convert to jest, we'll be able to rewrite these tests to get rid of the setTimeouts.

@sbrudz sbrudz merged commit 1cff744 into master Apr 27, 2020
@sbrudz sbrudz deleted the troubleshooting branch April 27, 2020 14:22
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.

Slow typing performance on long emails
2 participants