-
-
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 getSelectedBlocks
#17582
base: master
Are you sure you want to change the base?
Conversation
Looks good and is a simple and safe fix. However, since it only targets a specific scenario (one element in selection), I am afraid we may need to revisit it. The problem with current implementation is that it only looks at
Of course, we should respect this special case that is mentioned later:
Maybe it's even possible to limit the number of |
I implemented the suggestions. The ckeditor5/packages/ckeditor5-engine/src/model/treewalker.ts Lines 187 to 193 in 4883755
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also apply mentioned changes in the view tree walker.
* | ||
* @param position Position to jump to. | ||
*/ | ||
public jumpTo( position: Position ): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am worried that this method does not clone the position.
I know we should avoid cloning due to possible performance problems. However, it may lead to nasty bugs after using this function, when:
- tree walker will keep on iterating and will change the position, that you may want to use at some later point,
- or you will change that position offset and affect the tree walker.
So far, we don't have a guideline whether you (as integrator/developer) should always pass a "new" (cloned) position to API, or whether the functions will do it for you. We can add this note do API docs too, to help avoid creating unnecessary positions.
At the beginning of the performance initiative, I checked how how big impact has creating so many position clones on the overall performance. I was surprised how many positions we clone (a few hundreds thousands for some of the test samples). But I was also surprised that cutting it in half* didn't really have much impact. And in the profiler, I couldn't see that Position
constructor takes a lot of time. Not sure now, though, as we optimized a lot of stuff, and the percentage gains may be more significant.
* - this change turned to be bugged anyway, but still, I could measure the performance change.
Co-authored-by: Szymon Cofalik <[email protected]>
Suggested merge commit message (convention)
Other (engine): Improve performance of
getSelectedBlocks
when selection contains only one block element. Closes #17629.This improves the performance of the
tableHuge
performance test by ~20%.Use
Squash and merge
, as it's a fairly simply change with too many commits.