Optimize deep compare for formatted text#26749
Open
brrichards wants to merge 4 commits intomicrosoft:mainfrom
Open
Optimize deep compare for formatted text#26749brrichards wants to merge 4 commits intomicrosoft:mainfrom
brrichards wants to merge 4 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes formatted-text to Quill Delta generation by adding cursor-based “run” APIs to FormattedTextAsTree.Tree and updating buildDeltaFromTree to emit ops per uniform formatting run rather than per character.
Changes:
- Add
getUniformRun(startIndex, maxLength?)andtextString(startIndex, length)toFormattedTextAsTree.Tree(backed by a borrowed cursor implementation). - Update
buildDeltaFromTreeto walk the tree by uniform runs and callformatToQuillAttributes()once per run. - Add unit tests covering
getUniformRun/textString, including behavior around line atoms.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| packages/framework/react/src/text/formatted/quillFormattedView.tsx | Switch delta building to run-based traversal using the new tree APIs. |
| packages/dds/tree/src/text/textDomainFormatted.ts | Implement new cursor-based APIs (getUniformRun, textString) and expose them on the tree type. |
| packages/dds/tree/src/test/text/textDomainFormatted.spec.ts | Add tests for the new APIs, including line-atom scenarios. |
Comment on lines
+340
to
+345
| const limit = Math.min(length, arrayLength - startIndex); | ||
| let result = ""; | ||
|
|
||
| cursor.enterNode(startIndex); | ||
| for (let index = 0; index < limit; index++) { | ||
| if (index > 0 && !cursor.nextNode()) { |
Contributor
Author
There was a problem hiding this comment.
I have to assume that .join() is slower for small runs (a sentence, or a paragraph) compared to +=. Maybe the overhead cost is worth it?
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
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.
Summary
Optimize
buildDeltaFromTreewith cursor-based run detection.buildDeltaFromTreeiterated through every character individually viacharactersWithFormatting(), callingformatToQuillAttributesandJSON.stringifyper character for format comparison. To help with operations like this two new cursor-based API's have been added toFormattedTextAsTree.Tree:StringTextAtomandStringLineAtomcontent types.buildDeltaFromTreenow walks the tree in runs rather than character-by-character, callingformatToQuillAttributes()once per run instead of once per character.