-
Notifications
You must be signed in to change notification settings - Fork 562
Improve SharedTree comparator functions #26334
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
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.
Pull request overview
This PR improves comparator functions in the tree package by fixing a critical bug and enhancing performance:
Changes:
- Fixes a bug in
comparePartialRevisions(formerlycompareRevisions) that incorrectly compared "root" string equal to all numbers - Adds new comparator utility functions (
compareNumbers,comparePartialNumbers,comparePartialStrings) with proper handling of edge cases (NaN, Infinity, undefined) - Removes
defaultComparatorusage from sorted-btree library (performance improvement) - Introduces
newChangeAtomIdBTreehelper to replace manualnewTupleBTreecalls with proper comparators - Updates
newTupleBTreeandmergeTupleBTreessignatures for better API design - Adds comprehensive unit tests for all comparators
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/dds/tree/src/util/utils.ts | Removes Named interface and compareNamed function; adds new comparator functions (compareNumbers, comparePartialNumbers, comparePartialStrings) with proper edge case handling |
| packages/dds/tree/src/util/index.ts | Updates exports to include new comparator functions and remove deleted ones |
| packages/dds/tree/src/util/bTreeUtils.ts | Updates newTupleBTree to accept comparator parameter and mergeTupleBTrees to require non-undefined first parameter; improves tuple comparison implementation |
| packages/dds/tree/src/test/util/utils.spec.ts | Adds comprehensive unit tests for all new comparator functions including edge cases |
| packages/dds/tree/src/test/shared-tree/sharedTreeChangeCodec.spec.ts | Updates to use newChangeAtomIdBTree instead of newTupleBTree |
| packages/dds/tree/src/test/feature-libraries/modular-schema/modularChangesetUtil.ts | Updates to use newChangeAtomIdBTree instead of newTupleBTree |
| packages/dds/tree/src/test/feature-libraries/modular-schema/modularChangeFamily.spec.ts | Updates all usages to use newChangeAtomIdBTree with proper typed comparators |
| packages/dds/tree/src/feature-libraries/modular-schema/modularChangeFamily.ts | Implements newFieldIdKeyBTree with proper comparators; updates all BTree creation to use typed functions |
| packages/dds/tree/src/feature-libraries/modular-schema/modularChangeCodecV1.ts | Updates to use newChangeAtomIdBTree for decoding |
| packages/dds/tree/src/feature-libraries/modular-schema/index.ts | Changes from export type to export to also export newCrossFieldKeyTable function |
| packages/dds/tree/src/feature-libraries/index.ts | Adds export for newChangeAtomIdBTree |
| packages/dds/tree/src/feature-libraries/changeAtomIdBTree.ts | Adds newChangeAtomIdBTree helper function with proper comparators for ChangeAtomId tuples |
| packages/dds/tree/src/core/rebase/types.ts | Renames compareRevisions to comparePartialRevisions and fixes bug where string "root" compared equal to all numbers |
| packages/dds/tree/src/core/rebase/index.ts | Updates export name to comparePartialRevisions |
| packages/dds/tree/src/core/index.ts | Exports comparePartialRevisions as compareRevisions for backward compatibility |
| .gitignore | Adds .worktrees/ entry (appears unrelated to PR purpose) |
noencke
commented
Jan 30, 2026
noencke
commented
Jan 30, 2026
noencke
commented
Jan 30, 2026
bc3c4a1 to
a13a938
Compare
yann-achard-MS
approved these changes
Jan 30, 2026
yann-achard-MS
approved these changes
Jan 31, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
defaultComparator, which is slow (and came up in performance profiling).TupleBTrees to require comparators for their elements, and adds some additional compile time safety around the typing.RevisionTagcomparator which compared "root" equal to every number.