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

[UI initialization performance] Research how the UI is initialized (the flow) and which steps take significant amount of time #12682

Closed
Tracked by #12592
Reinmar opened this issue Oct 19, 2022 · 4 comments
Assignees
Labels
package:ui squad:core Issue to be handled by the Core team. type:performance This issue reports a performance issue or a possible performance improvement.

Comments

@Reinmar
Copy link
Member

Reinmar commented Oct 19, 2022

Part of #12592.

@Reinmar Reinmar added squad:core Issue to be handled by the Core team. package:ui labels Oct 19, 2022
@Reinmar Reinmar added the type:performance This issue reports a performance issue or a possible performance improvement. label Oct 19, 2022
@CKEditorBot CKEditorBot added the status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. label Oct 19, 2022
@niegowski niegowski self-assigned this Nov 9, 2022
@CKEditorBot CKEditorBot added status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. and removed status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. labels Nov 9, 2022
@niegowski
Copy link
Contributor

niegowski commented Nov 19, 2022

While analyzing the UI init flow, I checked different approaches to cut that time. 

Lazy render

The first idea was to postpone DOM element creation to the first moment that it would get visible. There are some view classes that have a separate isVisible property, so I was trying to move that property to the base View class and skip rendering until the first isVisible change. Unfortunately, there are a lot of places that expect the View#element property to be initialized by View#render(). The most common is FocusTracker#add( element ) and KeystrokeHandler#listenTo( element). Another obstacle to this approach is ViewCollection that expects a DOM element in ViewCollection#setParent().

This approach would be baked into the UI engine and would not require changes in features code but OTOH it could break some custom UIs that expect DOM element to be ready to use just after calling render().

Lazy init

Another approach was to postpone the construction of view instances that are expected to be not visible on the editor initialization (like dropdown panels, and widget toolbars). There is a branch that shows some improvements in UI init time: ck/12682-performance-reference...ck/12682-performance-lazy-init

This branch does not include all possible optimization places but already there is a visible performance improvement (see table at the bottom of this comment).

Toolbar grouping

We've seen that disabling this option improve the load times. In scenarios where the initialization time is critical, we recommend disabling it. See config.toolbar.

SVG parsing overhead

I checked whether SVG parsing (for IconView and WidgetTypeAround) takes a significant time (by disabling SVG loading completely) and I think that it does not impact the init time too much.

DOM element clone vs create

Another idea to verify was to clone existing DOM elements instead of creating new ones. In tests, it looked like it performed the same or even the performance was worse.

UI Init time measurements

Reference: https://github.com/ckeditor/ckeditor5/compare/ck/12682-performance-reference
Lazy init: ck/12682-performance-reference...ck/12682-performance-lazy-init
Without SVGs: ck/12682-performance-reference...ck/12682-performance-without-svg

image

@Reinmar
Copy link
Member Author

Reinmar commented Nov 21, 2022

Research summary:

  • 🔴  Lazy render is tricky. Possible, but may cause instability by increasing the complexity.
  • 🟢  Lazy initialization worked great. It's the first thing to change.
  • 🟡  We recommend avoiding automatic toolbar grouping when initialization performance is crucial. No actions from this item for now, though.
  • ❓  SVG parsing might be negatively impacting the performance. We were testing completely disabled SVGs. We'd need more time to verify a more realistic case where they are created, but without parsing.
  • 🔴 Cloning vs creating new elements. No difference or even worse results.

Plan:

@Reinmar
Copy link
Member Author

Reinmar commented Nov 21, 2022

  • 🟢  Lazy initialization worked great. It's the first thing to change.

Extracted to #12890.

@Reinmar
Copy link
Member Author

Reinmar commented Nov 21, 2022

  • ❓  SVG parsing might be negatively impacting the performance. We were testing completely disabled SVGs. We'd need more time to verify a more realistic case where they are created, but without parsing.

Extracted to #12891.

@Reinmar Reinmar closed this as completed Nov 21, 2022
@Reinmar Reinmar added this to the iteration 59 milestone Nov 21, 2022
@CKEditorBot CKEditorBot removed the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:ui squad:core Issue to be handled by the Core team. type:performance This issue reports a performance issue or a possible performance improvement.
Projects
None yet
Development

No branches or pull requests

3 participants