fix(cyclic): include yoz tests #448
Open
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.
PR #448 Update - Performance Optimizations
Changes Made
This update addresses the PR feedback from
copilot-pull-request-reviewerregarding performance optimizations inlib/cyclic.js.Performance Improvements
1. Optimized Path Checking (Line 26)
Issue:
Array.includes()was causing O(n) lookups for cycle detection in deep dependency graphs.Solution:
pathSet(a Set) alongside thepatharraypath.includes(id)topathSet.has(id)for O(1) lookupImpact: Significantly improved performance for deep dependency graphs (1000+ nodes).
2. Optimized Duplicate Cycle Detection (Lines 31-32)
Issue: Nested
some()/every()operations had O(nmk) complexity where:Solution:
normalized.join('->')cycleSet.has(cycleKey)Impact: Dramatically improved performance when many cycles are found (50+ cycles).
3. Code Quality Improvement
Issue: Adding the new parameters would violate ESLint's max-params rule (max 5 parameters).
Solution:
{path, pathSet, cycleSet, cycles}Test Coverage
New Comprehensive Test Suite
Created
test/cyclic.jswith 42 new tests organized into 9 categories:Basic Cycle Detection (7 tests)
Multiple Cycles (4 tests)
Cycle Normalization (3 tests)
Complex Graphs (4 tests)
Edge Cases (5 tests)
Performance Characteristics (3 tests)
Regression Tests (4 tests)
Data Structure Optimization (2 tests)
Correctness Guarantees (3 tests)
Test Results
Performance Benchmarks
Files Changed
lib/cyclic.js(+23, -7 lines)test/cyclic.js(+533 lines) - NEWBackward Compatibility
✅ Fully backward compatible
Summary
These optimizations address the PR feedback while maintaining 100% backward compatibility and correctness. The changes provide significant performance improvements for large codebases with deep dependency graphs and many circular dependencies, which was the original issue reported in #447.
The comprehensive test suite ensures the optimizations work correctly and will prevent future regressions.