-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Toolbar grouping should recalculate the styles less frequently #6194
Comments
Reducing I made a quick and a dirty demo ( Rich editor initialization(note, in order to do that you need to remove This editor contains a lot of icons so the difference will be the biggest. Total time show is relative to Evaluate Script. The
|
My question would be – do you think you can have a meaningful improvement (something above 50ms for a typical editor setup) in max 2 days of work? |
Now, for a reference here's a closer look at the execution timing on Almost entire total time of As of what we can do in limited time:
Unfortunately optimizing However reducing number of |
If you mean disabling grouping while the loop inside To sum up – it reduces the time |
The right thing to do (without increasing the tech debt) is:
Voilá. No avalanche of collection events and stuff when creating the toolbar. Which means no subsequent Additional profit: because the |
Yes, in this particular case yes.
I did some testing to verify this claim, and I can confirm that we'll see some gains in this area for table insertion dropdown. Results are not ground breaking, but it's clearly more optimal now. Tests performed using paste performance manual test by full refresh + clicking the table toolbar button. First 3 tests done on the latest
|
LGTM 👍 Thanks for verifying this. |
Moving to iteration 31 as this issue is blocked by #6319. |
There's a problem with this, our new Unfortunately So this way we're hitting a cyclic dependency here. I'll investigate further what are the options to get around this. |
Talked with @oleq today, and some ideas here: A brute-force solution might be to pull out ComponentFactory component creation into the Another solution is to create UIView after ClassicEditorUI, and initialize |
const factory = new ComponentFactory( editor );
const view = new ClassicEditorUIView( this.locale, this.editing.view, factory, {
shouldToolbarGroupWhenFull
} );
this.ui = new ClassicEditorUI( this, view, factory ); or this.ui = new ClassicEditorUI( this );
this.ui.view = new ClassicEditorUIView( this.locale, this.editing.view, this.ui.componentFactory, {
shouldToolbarGroupWhenFull
} ); |
I have implemented our conception outlined in previous comments (#6194 (comment), #6194 (comment), #6194 (comment)) on the The problem is that at a time of initialization of So the toolbar doesn't know how to create any button, which results with:
This is a second problem that surfaces only after implementation (first one was with component factory that has to be moved around).
|
sample/test case | _initToolbar before |
_initToolbar after |
relative before | relative after |
---|---|---|---|---|
editorinit (short, semantic content) | 452ms | 402ms (-50ms, -11%) | 46.8% of entire click handling time |
42.8% of entire click handling time |
all features | 898ms | 738ms (-160ms, -17.8%) | Browser splits initialization into two tasks, comparison would be misleading. | N/A |
You can explore the above performance results yourself: collection-batch-add.zip
Before
After
requestAnimationFrame
Another tossed idea was to use requestAnimationFrame
. At this point I'm not sure whether it would work.
I imagine that in _updateGrouping()
method we'd neet to add an rAF (request animation frame) listener to do the grouping upon layout recalc. We'd also need to make sure that no multiple pending rAF listeners are added (beacause it doesn't make sense to perform multiple _updateGrouping
subsequently).
I have a feeling that the first option (collection's extension) does not really address the general issue that we have with the UI – that during its initialization we do not control when some things related to the UI happen, so they happen at random times creating many reflows. That's a general issue that we may need to address one day. However, addressing it may require a major design effort, so most likely this is not the right moment to do that. And while I initially thought that rAF would be a part of the general solution, I'm having second doubts now. So, if the addBatch/removeBatch work for you and the results prove that, I don't see an issue with that approach for now. |
📝 Provide detailed reproduction steps (if any)
Currently toolbar recalculates the styles after adding each toolbar item.
It would be good to optimize it, and ideally it should do it only once.
Style recalculations make for 7.4% of total
_initToolbar
function time (in an editor with small semantic content) and this function makes a significant contribution to editor load time today.Here is a devtools profiler dump that can be viewed later on: editor-init-small.zip.
✔️ Expected result
Less style recalculations 🏃♀️
❌ Actual result
Styles are recalculated after adding each toolbar item 🐢 🐢 🐢 🐢 🐢 🐢 🐢 🐢 🐢
📃 Other details
This is a follow-up of #5880.
master
If you'd like to see this fixed sooner, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: