Avoid fetching selections when possible #3538
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On Blink,
document.getSelection()
forces layout which breaks the browser's optimization of batch DOM mutations. The impact on the performance is noticeable when you do a lot of DOM mutations andgetRange()
at the same time. It is worth noticing that editor mutation triggersgetRange()
(https://github.com/quilljs/quill/blob/d462f8000ffbaa3aab853809fb08f7809f828475/core/quill.js#L103) so the impact is non-trivial when you initialize many Quill instances at the same time.This PR optimizes Quill initialization when the container has not been inserted into the DOM tree yet. This enables an optimization possibility that users can insert the Quill container after the content is initialized. So instead of:
Users can:
As an example, when rendering 4000 Quill instances on a page, previously it took ~2min:
And after this PR, it only takes 14s: