Improve performance for command and selection changes #443
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.
What does this change?
We recently had a large article — 7000+ words and 242 elements, id
673f39b58f083ae557dd22af
— which was slow to load and edit in production.Using that article as a test case, this PR improves the performance of the elements plugin in two ways:
To help measure performance when profiling these changes, e857a1a adds a flag to disable performance-heavy features, which is useful for removing noise from serialisation, collab and dev tools code when profiling.
The table below gives the profiler script time for 30 keystrokes with the article above loaded in the demo page, with the above flag disabled. Tested on Chrome 131.0.6778.205 a 14-inch Macbook Pro, M1 Max, 2021:
About 4x faster.
How to test
main
and this branch, by copying and pasting the content from our CMS to the editor playground (yarn start
.) Can you feel the difference? You can also test in Composer following the instructions in the readme — I've included examples of both in GIFs here:How can we measure success?
Less pain editing large articles.
Is there anything more we can do?
On modern hardward, large articles with large numbers of elements like the above are still slow to load (something this PR does not attempt to address), and still have appreciable jank.
It looks like iterating over decorations, which we use to ensure nodeViews always update, takes up a fair few cycles, too. That might be another good place to start looking for performance improvements.
Loading improvements look like they're connecting to rendering. A few strategies we could try: