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

Unify MergeTree Walks into Single Interative Function #11603

Merged

Conversation

anthony-murphy
Copy link
Contributor

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.

@anthony-murphy anthony-murphy requested a review from a team as a code owner August 19, 2022 18:25
@@ -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);
Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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

@github-actions github-actions bot added area: dds Issues related to distributed data structures base: next PRs targeted against next branch labels Aug 19, 2022
post?: BlockAction<TClientData>,
start: number = 0,
end?: number,
localSeq?: number,
Copy link
Contributor Author

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

.vscode/launch.json Outdated Show resolved Hide resolved
@scarlettjlee
Copy link
Contributor

Why merge into next rather than main?

@anthony-murphy anthony-murphy deleted the unify-some-merge-tree-walks branch July 14, 2023 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: dds: sharedstring area: dds Issues related to distributed data structures base: next PRs targeted against next branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants