Skip to content

Fix O(n²) complexity in collect_inline_roots_in_range#403

Open
lainon1 wants to merge 2 commits intoDioxusLabs:mainfrom
lainon1:pr/traversal-on2
Open

Fix O(n²) complexity in collect_inline_roots_in_range#403
lainon1 wants to merge 2 commits intoDioxusLabs:mainfrom
lainon1:pr/traversal-on2

Conversation

@lainon1
Copy link
Copy Markdown
Contributor

@lainon1 lainon1 commented Apr 27, 2026

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).

Changed Vec.contains() (O(n)) to HashSet.contains() (O(1)) for deduplication
checks, reducing overall complexity from O(n²) to O(n).
@nicoburns
Copy link
Copy Markdown
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.
@lainon1
Copy link
Copy Markdown
Contributor Author

lainon1 commented Apr 27, 2026

Updated implementation - now starts traversal from first_anchor instead of root, eliminating the
need for any visited tracking by construction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants