-
-
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
Improve performance of attribute removal #4504
Comments
How much content did you test? Because I tested removing styles (quite a lot of them – I used a duplicated content from the remove-formatting.md docs page) from 50 paragraphs: It took 225ms to remove all the styles. I don't think this is a problem because those 50 paragraphs represent are not a short piece: |
OK, I can see that you used the content from https://github.com/ckeditor/ckeditor5-remove-format/issues/7. Sounds for me like an edge case. This content is causing some turbo deopts, but it does not look like a real content. We definitely have a problem, but I'd check with some real-life scenarios (copy-paste from other websites/word/etc) and prioritise it based on the results from these tests. |
Or maybe this is actually a pretty realistic scenario... |
The question would be whether it's simply a lot of operations to make or if attribute operations are slower than other. This could be affected by text nodes splitting and joining after each operation. |
OK, I found the main culprit. It was actually quite funny. I reduced the execution time from 34s to 1.5s which still isn't great, but it's much better. BEFORE: AFTER: The issue was this bit of code in viewRoot.on( 'change:children', ( evt, node ) => {
// Wait for the render to be sure that `<img/>` elements are rendered in the DOM root.
this.view.once( 'render', () => this._updateObservedElements( domRoot, node ) );
} ); Why is it a problem? It's actually 3 problems:
We need to rewrite this observer completely. The first thing that came to my mind was – can we use event capturing for The next thing to look into would be |
I've found out that the longer the text is in single paragraph the longer the method take. This is counterintuitive to me as I's suspect the same number of operations - but maybe there's something more going on which is dependent on the text length not the number of attributes. |
The same happens the other way around too -- when you add multiple attributes at the same time. This is a case in track changes. I debugged it and got a very similar performance chart. |
Unfortunately, ckeditor/ckeditor5-image#335 does not resolve this issue completely. The performance is still fundamentally wrong. I did some profiling and out of 8s that the whole thing takes, 3.3s are spent in Here are stats of view element constructor calls, split per element name. In the arrays I stored the As you can see, in summary, the constructor is called 70k times 🤯 👉 70.000 times 👈 Most of the time, in this case, with |
Nope. The number of times we call this with |
Fix: Improved markup operation performance of the editor with the image plugin enabled. See ckeditor/ckeditor5#4504.
I closed ckeditor/ckeditor5-image#335 but I think we should keep this issue opened. I think that a reasonable time for this content is around 1s. So there's still 80% to go. |
I extracted the image load observer to #5766 and I'd remove this ticket from the iteration as there's more to do here. |
In this case, there are 30k model nodes (10k elements and 20k text nodes) created, even though the final document has 3k nodes. Again, we're executing |
Okeydokey – I was able to take However, we should still check if we can save some time here. Unfortunately, in both cases (remove format and data loading) this will not be a micro-optimization any more (unless someone knows how to shove some time off the
|
@Reinmar would you mind creating a manual sample similar to the ones I've created for the memory leak tests?
This would help to manually test various improvements and compare results in the team. |
As I commented in #2336 (comment). We reduced the time over 10x. NICE :) |
While working on remove formatting (ckeditor/ckeditor5-remove-format#7) we found that removing attributes from relatively simply code takes too much time.
For repro case see ckeditor/ckeditor5-remove-format#7.
The text was updated successfully, but these errors were encountered: