Refacto/33 parallel parsing#34
Conversation
📝 WalkthroughWalkthroughPython directory parsing now runs concurrently with per-file result indexing and post-parse cross-file resolution. Parser ownership uses local RAII wrappers, scanner timing is reported, benchmark tooling and documentation are added, and CMake links thread support. ChangesParallel Python Parsing
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant scan_main
participant PythonParser
participant WorkerThreads
participant DbInserter
scan_main->>PythonParser: parseDirectory(target)
PythonParser->>WorkerThreads: parse files concurrently
WorkerThreads-->>PythonParser: indexed ParseResults
PythonParser-->>scan_main: resolve cross-file calls and return results
scan_main->>DbInserter: insertAll(results)
DbInserter-->>scan_main: return insertion status
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
scripts/bench_parser.sh (1)
35-39: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valuePrefer
-pthreadover-lpthreadfor the compiler flag.
-pthreadis the recommended way to enable threading support with g++ — it sets both the correct preprocessor defines and linker flags.-lpthreadalone works on Linux/glibc but may not on all platforms. Since this is a benchmark script, correctness of the binary matters for valid measurements.♻️ Suggested change
g++ -O2 -std=c++17 -I"$ROOT/src" -I"$DEPS/tree-sitter-src/lib/include" -I"$ROOT/third_party/sqlite" \ "$ROOT/src/scan_main.cpp" "$ROOT/src/db/DbInserter.cpp" "$ROOT/src/db/db.cpp" \ "$ROOT/src/parser/PythonParser.cpp" "$ROOT/src/parser/ParserRegistry.cpp" \ "$OUT"/ts.o "$OUT"/tsp_parser.o "$OUT"/tsp_scanner.o "$OUT"/sqlite3.o \ - -lpthread -ldl -o "$OUT/scanner_bench" + -pthread -ldl -o "$OUT/scanner_bench"🤖 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 `@scripts/bench_parser.sh` around lines 35 - 39, Update the g++ link command in the benchmark build to use the compiler’s -pthread option instead of the standalone -lpthread flag, while preserving the existing source files, libraries, and output target.
🤖 Prompt for all review comments with 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.
Inline comments:
In `@src/parser/PythonParser.cpp`:
- Around line 973-978: Update the catch-all block in the parseFile loop to log
the failed file path to std::cerr before continuing, using files[i] to identify
the file while preserving the existing behavior of leaving results[i] empty and
processing remaining files.
---
Nitpick comments:
In `@scripts/bench_parser.sh`:
- Around line 35-39: Update the g++ link command in the benchmark build to use
the compiler’s -pthread option instead of the standalone -lpthread flag, while
preserving the existing source files, libraries, and output target.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 843a35b5-dfd7-49b9-bfe4-ef79af5fae3e
⛔ Files ignored due to path filters (6)
output/sherlock/base_class.csvis excluded by!**/*.csvoutput/sherlock/class.csvis excluded by!**/*.csvoutput/sherlock/file.csvis excluded by!**/*.csvoutput/sherlock/function.csvis excluded by!**/*.csvoutput/sherlock/link.csvis excluded by!**/*.csvoutput/sherlock/param.csvis excluded by!**/*.csv
📒 Files selected for processing (7)
CMakeLists.txtscripts/bench_parser.shsrc/algo/Scoring.hsrc/parser/BENCHMARK.mdsrc/parser/PythonParser.cppsrc/parser/PythonParser.hsrc/scan_main.cpp
💤 Files with no reviewable changes (1)
- src/parser/PythonParser.h
| try { | ||
| results[i] = parseFile(files[i], rootStr); | ||
| } catch (...) { | ||
| // 해당 파일만 빈 결과로 남기고 계속 진행. | ||
| // (std::thread에서 예외가 새면 프로세스가 종료됨) | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Log failed file paths for debuggability.
The catch (...) block silently swallows parse exceptions. When a file fails to parse, there is no indication which file caused the failure, making it difficult to diagnose issues in large repositories. A simple std::cerr with the file path would help.
💡 Suggested improvement
try {
results[i] = parseFile(files[i], rootStr);
} catch (...) {
- // 해당 파일만 빈 결과로 남기고 계속 진행.
- // (std::thread에서 예외가 새면 프로세스가 종료됨)
+ // 해당 파일만 빈 결과로 남기고 계속 진행.
+ // (std::thread에서 예외가 나면 프로세스가 종료됨)
+ std::cerr << "[PythonParser] Parse failed: " << files[i] << "\n";
}📝 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.
| try { | |
| results[i] = parseFile(files[i], rootStr); | |
| } catch (...) { | |
| // 해당 파일만 빈 결과로 남기고 계속 진행. | |
| // (std::thread에서 예외가 새면 프로세스가 종료됨) | |
| } | |
| try { | |
| results[i] = parseFile(files[i], rootStr); | |
| } catch (...) { | |
| // 해당 파일만 빈 결과로 남기고 계속 진행. | |
| // (std::thread에서 예외가 나면 프로세스가 종료됨) | |
| std::cerr << "[PythonParser] Parse failed: " << files[i] << "\n"; | |
| } |
🤖 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/parser/PythonParser.cpp` around lines 973 - 978, Update the catch-all
block in the parseFile loop to log the failed file path to std::cerr before
continuing, using files[i] to identify the file while preserving the existing
behavior of leaving results[i] empty and processing remaining files.
Summary
PythonParser::parseDirectory의 파일 단위 파싱을 멀티스레드로 병렬화하여 스캔 속도를 개선한다. 사전 벤치마크로 파싱이 전체 스캔 시간의 71%를 차지하는 지배 병목임을 확인했고(src/parser/BENCHMARK.md), 병렬화 결과 파싱 5.9배 / 전체 스캔 2.5배 개선을 달성했다. 병렬화 전후 스캔 결과는 DB 덤프 기준 완전히 동일하다.
Changes
성능 비교 (Python 3.11 stdlib, 680개 파일, 12코어, -O2, 3회 측정)
파싱
재현: scripts/bench_parser.sh
정확성 검증
Related Issue
Closes #33
Checklist