-
Notifications
You must be signed in to change notification settings - Fork 22
Optimize dist-archive by preventing descent into ignored directories #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
10
commits into
main
Choose a base branch
from
copilot/fix-recursiveiteratoriterator-performance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+598
−20
Conversation
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
Co-authored-by: swissspidy <[email protected]>
Updated the RecursiveFilterIterator to use hasChildren() instead of accept() to prevent descending into ignored directories. This ensures: 1. Ignored directories are still yielded (needed for exclude lists in targz format) 2. We don't descend into them (performance optimization) 3. All existing tests pass Co-authored-by: swissspidy <[email protected]>
Updated hasChildren() to be more conservative when skipping descent: - Only skip for top-level ignored directories where children would also be ignored - This handles complex patterns like "frontend/*" with "!/frontend/build/" - Still provides performance benefit for common cases like node_modules and .git - All 27 distignore test scenarios now pass Co-authored-by: swissspidy <[email protected]>
- Use substr() instead of str_replace() for path manipulation to avoid edge cases - Add comment explaining the use of 'test' as a probe filename - Replace Bash-specific syntax with portable POSIX shell commands in tests - Fix code style (trailing whitespace) Co-authored-by: swissspidy <[email protected]>
Copilot
AI
changed the title
[WIP] Fix performance issue with RecursiveIteratorIterator in file scanning
Optimize dist-archive by preventing descent into ignored directories
Dec 23, 2025
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This comment was marked as resolved.
This comment was marked as resolved.
Introduced an ignored_cache array in Distignore_Filter_Iterator to cache the results of isPathIgnored() checks. This eliminates duplicate checks: - Once in hasChildren() when deciding whether to descend into directories - Once in get_file_list() when categorizing files/directories The cache is shared between both methods via the new isPathIgnoredCached() method, reducing redundant gitignore pattern matching for directories. Co-authored-by: swissspidy <[email protected]>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Moved the filtering logic from get_file_list() into the iterator's accept() method as suggested. This provides a more profound optimization: - accept() now filters out ignored FILES immediately (not yielded) - Ignored DIRECTORIES are still yielded (for exclude tracking) but won't be descended into per hasChildren() - get_file_list() loop now only processes items that pass the filter, significantly reducing iterations - Excluded files are tracked in the iterator and available via getExcludedFiles() Performance: Iterator now yields only ~5 items instead of 200+ for a directory with 200 ignored files, while maintaining correct behavior for complex gitignore patterns with negations. Co-authored-by: swissspidy <[email protected]>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Created 9 test methods covering all major functionality: - test_filters_ignored_files: Verifies ignored files are not yielded - test_tracks_ignored_directories: Ensures directories are tracked but files inside are filtered - test_get_excluded_files: Tests getExcludedFiles() method - test_caching_avoids_duplicate_checks: Verifies caching behavior - test_has_children_prevents_descent: Tests that hasChildren() prevents descent into ignored dirs - test_negation_patterns: Validates complex negation patterns work correctly - test_get_error_for_item_returns_null: Tests error handling - test_nested_directory_filtering: Ensures multi-level directories are handled - test_children_share_state: Verifies child iterators share cache and excluded files All 9 tests pass with 24 assertions. Tests include setup/teardown with temporary directories. Co-authored-by: swissspidy <[email protected]>
This comment was marked as resolved.
This comment was marked as resolved.
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.
Performance Optimization Complete ✅
RecursiveFilterIteratorclass to filter out ignored directories before iterationget_file_list()to use the filter iterator to prevent descending into ignored directoriesSummary
This PR fixes a critical performance issue where
RecursiveIteratorIteratorwas scanning ALL files in ignored directories before filtering them out. For projects with largenode_modulesdirectories (30,000+ files), this made the command nearly unusable.Solution: Introduced a
RecursiveFilterIteratorthat filters ignored files directly in theaccept()method, preventing them from being yielded to the foreach loop. The iterator:Performance Impact:
Changes:
Distignore_Filter_Iteratorwith smart filtering in accept() methodget_file_list()to leverage iterator's filtering (reduced logic)Test Coverage:
Compatibility: All 27 existing Behat test scenarios pass, plus new performance test added. All 9 PHPUnit tests pass.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.