perf: O(1) document entry lookups in ProjectNode #1293
Merged
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
Optimizes document entry lookups in
ProjectNodefrom O(n) iteration to O(1) hash-based lookups.This PR contains 3 distinct commits, each addressing a specific concern:
1. Preparatory Refactor: File path comparison (4 files)
Replaces object identity comparison (
===) with file path comparison when matchingDocumentEntryNodeinstances.Why this matters:
Changed files:
GlobalMenuPass.php- root document lookupToctreeValidationPass.php- root document checkRenderContext.php-getDocumentNodeForEntry()DocumentTreeIterator.php-current()2. Performance Improvement: O(1) caching (1 file)
Adds hash-based O(1) lookups to
ProjectNode:Changes to
ProjectNode.php:getRootDocumentEntry()getDocumentEntry()by file pathsetDocumentEntries()viaaddDocumentEntry()reset()DocumentEntryNode[]→array<string, DocumentEntryNode>3. Test Adaptation (1 file)
Updates
FunctionalTest.phpto usewithIsRoot(true)instead of manually creating aDocumentEntryNodethat gets overwritten by the compiler.Performance Impact
getRootDocumentEntry()getDocumentEntry($file)This is particularly impactful for large documentation projects with hundreds or thousands of documents.
See Performance Analysis Report for detailed benchmarks.
Test Plan
Related PRs
All PRs can be merged independently in any order.