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
Unify MergeTree Walks into Single Interative Function #11603
Unify MergeTree Walks into Single Interative Function #11603
Conversation
| @@ -837,7 +844,7 @@ export class MergeTree { | |||
| offset = start; | |||
| return false; | |||
| }; | |||
| this.searchBlock(this.root, pos, 0, refSeq, clientId, { leaf }, undefined, localSeq); | |||
| this.nodeMap(refSeq, clientId, leaf, undefined, undefined, pos, pos + 1, localSeq); | |||
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.
search block was the wrong method here, as it stops at every segment, whereas nodemap uses the tree to optimally find the position.
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.
What consequences did that have? perf?
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.
walking the tree with node walk is O(log N), whereas walking all segments with search will be O(N), so yeah it was perf
| post?: BlockAction<TClientData>, | ||
| start: number = 0, | ||
| end?: number, | ||
| localSeq?: number, |
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.
bonus. adding local seq here was cheap, which helps get containing segment, which helps for rebase, rollback, re-connect etc
…to unify-some-merge-tree-walks
|
Why merge into next rather than main? |
Description
In merge tree there were multiple near duplicate methods for walking the tree. Additionally, all these methods were recursive. This change unifies the tree walks into a single method, that is iterative rather than recursive. The primary motivation for this change in related to #1009 where it is necessary to do tree walks to shift local references for each undo/redo, as the tree grew these walks grew deeper, and the repeated stack allocations of the recursive calls lead to performance issues. In addition, removing all the duplicated variations will make maintenance easier, and should reduce bundle size.