perf!: replace LinkedList with Vector for child node storage#79
Merged
Conversation
Replace LinkedList (O(n) index access) with Vector (O(1) index access) for the internal children list. This eliminates O(n²) patterns in rendering, ID searches, and tag searches. Benchmarks with 1000 children: - toHTML(): 9x faster (134ms → 15ms) - getChildByID(): 35x faster (239ms → 7ms) - index-based loop: 363x faster (105ms → 0.3ms) BREAKING CHANGE: children() now returns Vector instead of LinkedList. Code that type-hints LinkedList for children() return must update. Closes #66
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #79 +/- ##
============================================
- Coverage 98.44% 98.31% -0.13%
- Complexity 898 917 +19
============================================
Files 6 6
Lines 1799 1843 +44
============================================
+ Hits 1771 1812 +41
- Misses 28 31 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Replace
LinkedListwithVectorforHTMLNodechild storage, eliminating O(n²) index-access patterns.Motivation
LinkedList::get($index)is O(n), making loops over children O(n²). With 1000 children, rendering alone took 134ms. Fixes #66.Changes
$childrenListfromLinkedListtoVectorinHTMLNoderemoveElement()calls withremove()(Vector API)remove()calls withremoveAt()getChild()to return null instead of throwingHow to Test / Verify
All 308 existing tests pass. Benchmark results with 1000 children:
Breaking Changes and Migration Steps
children()return type changes fromLinkedListtoVectorLinkedListforchildren()return must change toVectorVector::get()throwsOutOfRangeExceptionon invalid index (mitigated by bounds check ingetChild())Checklist
composer fix-cs) — N/A, minimal changeRelated issues
Closes #66