Skip to content

Commit 86901f3

Browse files
akirasosaclaude
andcommitted
perf(copy): limit find depth for simple directory patterns
When copying directories with simple basename patterns (e.g., `.serena`, `node_modules`), `find` was scanning the entire repository tree recursively. In repos with large directories like `node_modules` (2GB+), this caused ~11 seconds of unnecessary I/O per pattern. Add `-maxdepth 1` for non-slash patterns since `gtr.copy.includeDirs` entries are typically top-level directories. Patterns with slashes (e.g., `vendor/bundle`) retain recursive behavior via `-path`. Before: ~11s per pattern (full recursive find) After: ~0.03s per pattern (top-level only) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 161b478 commit 86901f3

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

lib/copy.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,11 @@ copy_directories() {
331331
# Find directories matching the pattern
332332
# Use -path for patterns with slashes (e.g., vendor/bundle), -name for basenames
333333
# Note: case inside $() inside heredocs breaks Bash 3.2, so compute first
334+
# Use -maxdepth 1 for simple basenames to avoid scanning entire repo (e.g., node_modules)
334335
local find_results
335336
case "$pattern" in
336337
*/*) find_results=$(find . -type d -path "./$pattern" 2>/dev/null) ;;
337-
*) find_results=$(find . -type d -name "$pattern" 2>/dev/null) ;;
338+
*) find_results=$(find . -maxdepth 1 -type d -name "$pattern" 2>/dev/null) ;;
338339
esac
339340

340341
while IFS= read -r dir_path; do

0 commit comments

Comments
 (0)