perf: native complexity for all languages + phase benchmarks#149
perf: native complexity for all languages + phase benchmarks#149carlos-alm merged 1 commit intomainfrom
Conversation
Eliminate WASM parser initialization (~200ms) during native engine builds by computing complexity metrics in Rust for all supported languages, not just JS/TS/TSX. Rust complexity module rewritten with configurable LangRules struct matching the JS-side COMPLEXITY_RULES. Full algorithm ported including three else/elif patterns (Pattern A: else wraps if for JS/C#/Rust, Pattern B: explicit elif for Python/Ruby/PHP, Pattern C: alternative field for Go/Java), switch-like node handling, and leaf token guards. All 8 extractors (JS, Python, Go, Rust, Java, C#, PHP, Ruby) now call compute_function_complexity with language-specific rules instead of returning complexity: None. JS-side safety net: COMPLEXITY_EXTENSIONS guard in buildComplexityMetrics skips needsFallback check for files whose language has no complexity rules. Build phase timing added to buildGraph (parse, insert, resolve, edges, structure, roles, complexity) with phase breakdown table in benchmark reports. Impact: 32 functions changed, 50 affected
|
Claude finished @carlos-alm's task —— View job PR Review: Native Complexity Engine Performance ✅Reviewing performance improvements for native complexity computation across all languages. Todo List:
Root Cause Analysis ✅Problem Being Solved: The Key Issue: Lines 1398-1413 in Why This Approach: The solution implements native complexity computation in Rust with faithful language rules ported from JS, eliminating the need for WASM fallback entirely when native engine is available. Critical ConcernsNone identified. This is a well-architected performance optimization that:
Technical HighlightsRust Implementation Quality ⭐Excellent faithful port from JS to Rust in
Performance Impact ⭐Measurable improvement claims:
Test Coverage Excellence ⭐
Final Recommendation
Outstanding work! This PR demonstrates excellent engineering practices and will provide meaningful performance improvements for all codegraph users. |
Greptile SummaryRewrote Rust complexity engine with configurable Key changes:
Performance impact:
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[buildGraph] --> B[parseFilesAuto]
B --> C{Native engine available?}
C -->|Yes| D[Native extractors parse + compute complexity]
C -->|No| E[WASM parsers extract symbols only]
D --> F[buildComplexityMetrics]
E --> F
F --> G{Check all files}
G --> H{Has _tree cached?}
H -->|Yes| I[Use cached tree for WASM computation]
H -->|No| J{File extension in COMPLEXITY_EXTENSIONS?}
J -->|No| K[Skip - no rules for language]
J -->|Yes| L{All functions have pre-computed complexity?}
L -->|Yes| M[Use native complexity - no WASM needed]
L -->|No| N[Initialize WASM parsers - fallback mode]
N --> O[Re-parse file with WASM]
O --> P[Compute complexity from AST]
I --> P
M --> Q[Insert into function_complexity table]
P --> Q
K --> Q
Q --> R[Return with phase timings]
style D fill:#90EE90
style M fill:#90EE90
style N fill:#FFB6C1
style O fill:#FFB6C1
Last reviewed commit: a61905a |
Summary
complexity.rswith configurableLangRulesstruct (faithful port of JSCOMPLEXITY_RULES). All 8 extractors (JS, Python, Go, Rust, Java, C#, PHP, Ruby) now compute complexity natively instead of returningcomplexity: NoneneedsFallbackis nowfalsefor all languages — no WASM parser initialization (~200ms saved). Complexity phase drops from ~340ms to ~20msbuildGraphreturns per-phase timings (parse, insert, resolve, edges, structure, roles, complexity). Benchmark scripts capture and render a Native vs WASM phase comparison tableRoot cause
The
buildComplexityMetrics()fallback check scanned all files for missingd.complexity. Non-JS files (e.g. Rust sources incrates/) hadcomplexity: Nonefrom native extractors, triggering WASM initialization for all 10 grammars — even though the native engine had already parsed everything.Test plan