Fix O(n²) complexity in collect_inline_roots_in_range#403
Open
lainon1 wants to merge 2 commits intoDioxusLabs:mainfrom
Open
Fix O(n²) complexity in collect_inline_roots_in_range#403lainon1 wants to merge 2 commits intoDioxusLabs:mainfrom
lainon1 wants to merge 2 commits intoDioxusLabs:mainfrom
Conversation
Changed Vec.contains() (O(n)) to HashSet.contains() (O(1)) for deduplication checks, reducing overall complexity from O(n²) to O(n).
Member
|
Hmm... I think we ought to use traversal logic that only ever visits each node once by construction. Then we could just check whether we've reached the end node yet, and wouldn't need to keep track of visited nodes at all. |
Based on suggestion from nicoburns: start traversal from first_anchor instead of root, ensuring we only visit nodes in range by construction. No HashSet needed - eliminates duplicate check overhead.
Contributor
Author
|
Updated implementation - now starts traversal from first_anchor instead of root, eliminating the |
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.
Changed Vec.contains() (O(n)) to HashSet.contains() (O(1)) for deduplication checks in collect_inline_roots_in_range, reducing overall complexity from O(n²) to O(n).