Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-05-18 - fs.readdirSync performance bottleneck

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

학습 기록 날짜가 현재 PR 시점과 불일치합니다.

Line 1의 2024-05-18은 이번 변경(PR 생성일: 2026-06-08)과 맞지 않아 추적성을 떨어뜨립니다. 실제 기록 시점으로 맞춰 주세요.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.jules/bolt.md at line 1, 헤더에 사용된 날짜 문자열 "2024-05-18" (문구: "## 2024-05-18 -
fs.readdirSync performance bottleneck")이 PR 생성일과 불일치하므로 해당 헤더의 날짜를 PR 시점인
"2026-06-08"로 갱신하여 기록 시점을 일치시키세요.

**Learning:** Found a severe performance bottleneck in `walkFiles` which combines `fs.readdirSync` with `fs.statSync`. This forces synchronous I/O blocks for every file/directory just to determine if it's a directory.
**Action:** Replace `fs.readdirSync(..., { withFileTypes: true })` which returns `Dirent` objects, avoiding the need for individual `statSync` calls to check `isDirectory()`. This improves I/O performance significantly when traversing large file trees in this CLI app.
7 changes: 3 additions & 4 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ export function projectKey(start = process.cwd()): string | null {
export function walkFiles(root: string, predicate: (path: string) => boolean): string[] {
if (!existsSync(root)) return [];
const files: string[] = [];
for (const entry of readdirSync(root)) {
const path = join(root, entry);
const stat = statSync(path);
if (stat.isDirectory()) files.push(...walkFiles(path, predicate));
for (const entry of readdirSync(root, { withFileTypes: true })) {
const path = join(root, entry.name);
if (entry.isDirectory()) files.push(...walkFiles(path, predicate));
else if (predicate(path)) files.push(path);
Comment on lines +30 to 33

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

심볼릭 링크 디렉토리 순회 누락 회귀가 발생합니다.

Line 32에서 entry.isDirectory()만 검사하면 디렉토리 심볼릭 링크를 재귀 순회하지 않습니다. 기존 statSync(path).isDirectory() 기반 동작과 달라져, 링크된 하위 트리의 .md 파일이 누락될 수 있습니다(예: listUseCases, doctor 대상 해석 경로).

수정 제안 (성능 이점 유지 + 링크 디렉토리만 폴백 stat)
 for (const entry of readdirSync(root, { withFileTypes: true })) {
   const path = join(root, entry.name);
-  if (entry.isDirectory()) files.push(...walkFiles(path, predicate));
+  const isDir = entry.isDirectory() || (entry.isSymbolicLink() && statSync(path).isDirectory());
+  if (isDir) files.push(...walkFiles(path, predicate));
   else if (predicate(path)) files.push(path);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for (const entry of readdirSync(root, { withFileTypes: true })) {
const path = join(root, entry.name);
if (entry.isDirectory()) files.push(...walkFiles(path, predicate));
else if (predicate(path)) files.push(path);
for (const entry of readdirSync(root, { withFileTypes: true })) {
const path = join(root, entry.name);
const isDir = entry.isDirectory() || (entry.isSymbolicLink() && statSync(path).isDirectory());
if (isDir) files.push(...walkFiles(path, predicate));
else if (predicate(path)) files.push(path);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/files.ts` around lines 30 - 33, The directory walk misses symlinked
directories because it only checks entry.isDirectory(); update the logic in
walkFiles so that it also follows directory symlinks by falling back to a stat
check when needed (e.g., treat the entry as a directory if entry.isDirectory()
|| (entry.isSymbolicLink() && statSync(path).isDirectory())); keep the fast path
using entry.isDirectory() to preserve performance, and when the combined check
determines a directory, recurse via files.push(...walkFiles(path, predicate));
otherwise apply predicate(path) as before.

}
return files.sort();
Expand Down