question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance degradation with DOM mutation events

See original GitHub issue

The usage of DOM mutation events in Quill (specifically, DOMNodeInserted from c4d897838a463d8396c9e93ec9faf5e9bca5566d) significantly degrades the performance of DOM node insertions and removals on the entire document. Additionally, the API is deprecated.

More information about the performance effects of DOM mutation events can be found on MDN: https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Mutation_events In particular:

Adding DOM mutation listeners to a document profoundly degrades the performance of further DOM modifications to that document (making them 1.5 - 7 times slower!). Moreover, removing the listeners does not reverse the damage.

The listener was originally added to address #1437 — I’m not sure why adding mutation listeners would fix that bug, but it would be nice to find another solution.

I have tried substituting the mutation event listener with a MutationObserver, but using MutationObserver doesn’t fix the bug.

Steps for Reproduction

  1. Visit https://quilljs.com
  2. Run the following code in console:
document.body.addEventListener('click', () => {
    console.time();
    for (let i = 0; i < 1000; i++) {
        const div = document.createElement('div');
        document.body.appendChild(div);
    }
    console.timeEnd();
});
  1. Click on the page and observe timing information
  2. Run the same code on another site, to compare

Expected behavior: DOM node insertions are fast

Actual behavior: DOM node insertions are painfully slow

Platforms: This seems to affect all major browsers and platforms

Version: >= 1.2.5, when the listener was added

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:27
  • Comments:26 (1 by maintainers)

github_iconTop GitHub Comments

27reactions
echan00commented, Jul 29, 2019

Any plans to do something about this?

15reactions
vinzzzbcommented, Apr 30, 2020

Any update?

Read more comments on GitHub >

github_iconTop Results From Across the Web

MutationEvent - Web APIs | MDN
Chrome Edge MutationEvent. Deprecated Full support. Chrome1. Toggle history Full support. Edge12. To... attrChange. Deprecated Full support. Chrome1. Toggle history Full support. Edge12. To... attrName. Deprecated...
Read more >
performance impact of DOM mutation listeners - Google Groups
Mutation listeners cause slowdown in two ways: 1) Firing the event takes time O(tree depth at which mutation happened), with a constant that...
Read more >
Mutation events
The practical reasons to avoid the mutation events are performance issues and cross-browser support. Performance Section. Adding DOM mutation listeners to a ...
Read more >
html - DOM mutation events replacement - Stack Overflow
The reason that mutation events was deprecated was because of huge performance issues. The replacement is Mutation Observers, ...
Read more >
Detect DOM changes with mutation observers
Mutation Events are useful, but at the same time they create some performance issues. The Events are slow and they are fired too...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found