fix(bench): attribute unified walk time to per-phase timers#858
fix(bench): attribute unified walk time to per-phase timers#858carlos-alm merged 4 commits intomainfrom
Conversation
The analysis engine runs AST/complexity/CFG/dataflow visitors in a single DFS walk, then delegates to buildXxx functions for DB writes. The walk time was stored in a hidden _unifiedWalkMs field while the reported phase timers only captured the DB-write tail. This made WASM 1-file incremental benchmarks show ~0ms for CFG/dataflow/complexity (the real work was done in the unified walk but never attributed). Now each file's walk time is distributed proportionally among active visitors, and delegateToBuildFunctions accumulates (+=) rather than overwrites (=) so both walk + DB-write time are captured.
|
Claude finished @carlos-alm's task —— View job PR Review CompleteReviewing PR #858: fix(bench): attribute unified walk time to per-phase timers Root Cause AnalysisProblem Being Solved: WASM 1-file incremental rebuilds showed misleading benchmark results with ~0ms for AST/complexity/CFG/dataflow phases, while all the actual computation work was being done but not attributed correctly. Why This Approach: This is a legitimate timing attribution fix addressing a real measurement issue. The unified walk ( Risk Assessment: Low risk. This is purely a measurement/observability fix with no functional behavior changes. Backlog Compliance
Critical ConcernsNone identified. This is a clean, targeted fix. Code Quality Analysis✅ Strengths
🔍 Implementation Details
✅ Edge Cases Handled
📊 Benchmark ImpactThis fix will make WASM 1-file incremental benchmarks show realistic phase breakdown instead of misleading ~0ms values. Native engine timers already worked correctly, so this achieves parity. Final Recommendation
This PR should be merged — it fixes misleading benchmark data without introducing any functional changes or risks. |
Greptile SummaryThis PR fixes a benchmarking accuracy issue in Key changes:
The fix is correct and well-scoped. All prior review concerns (the "proportionally" vs "equally" wording) have been resolved in the head commit. Confidence Score: 5/5Safe to merge — changes are limited to timing instrumentation with no effect on analysis correctness or DB output. Both changed files touch only benchmarking/timing fields. The core logic fix (+= instead of =) is straightforward and correct. The prior review concern about 'proportionally' vs 'equally' wording has been resolved in the head commit. All tests pass. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant RA as runAnalyses
participant EW as ensureWasmTreesIfNeeded
participant SW as setupVisitors
participant WV as walkWithVisitors
participant PT as timing (per-phase)
participant DB as delegateToBuildFunctions
RA->>EW: pre-parse WASM trees
loop for each file with _tree
RA->>SW: setupVisitors(db, relPath, symbols, langId, opts)
SW-->>RA: {visitors, astVisitor, complexityVisitor, cfgVisitor, dataflowVisitor}
Note over RA: walkStart = performance.now()
RA->>WV: walkWithVisitors(rootNode, visitors, langId, walkerOpts)
WV-->>RA: results (AST / complexity / CFG / dataflow)
Note over RA: walkMs = elapsed; share = walkMs / activeCount
RA->>PT: astMs += share
RA->>PT: complexityMs += share
RA->>PT: cfgMs += share
RA->>PT: dataflowMs += share
end
Note over RA: _unifiedWalkMs = total loop wall-clock
RA->>DB: delegateToBuildFunctions(db, fileSymbols, timing)
DB->>PT: astMs += DB-write elapsed
DB->>PT: complexityMs += DB-write elapsed
DB->>PT: cfgMs += DB-write elapsed
DB->>PT: dataflowMs += DB-write elapsed
Reviews (2): Last reviewed commit: "fix(bench): clarify timing comments per ..." | Re-trigger Greptile |
| // Unified pre-walk: run all applicable visitors in a single DFS per file. | ||
| // Time each file's walk and distribute proportionally among active visitors | ||
| // so that phase timers (astMs, complexityMs, etc.) reflect real work — not | ||
| // just the DB-write tail in delegateToBuildFunctions. |
There was a problem hiding this comment.
"Proportionally" vs "equally" in comment
The comment says "distribute proportionally among active visitors" but the implementation divides walkMs equally (walkMs / activeCount). Equal distribution is a valid approximation, but "proportionally" implies the share reflects each visitor's actual work — which it doesn't. This could mislead future readers who then expect e.g. a complexity-heavy visitor to show a larger share.
| // Unified pre-walk: run all applicable visitors in a single DFS per file. | |
| // Time each file's walk and distribute proportionally among active visitors | |
| // so that phase timers (astMs, complexityMs, etc.) reflect real work — not | |
| // just the DB-write tail in delegateToBuildFunctions. | |
| // Unified pre-walk: run all applicable visitors in a single DFS per file. | |
| // Time each file's walk and distribute equally among active visitors | |
| // so that phase timers (astMs, complexityMs, etc.) reflect real work — not | |
| // just the DB-write tail in delegateToBuildFunctions. |
There was a problem hiding this comment.
Fixed in fa5e686 — changed "proportionally" to "equally" in the comment, matching what the code actually does.
Codegraph Impact Analysis2 functions changed → 1 callers affected across 1 files
|
- Change "proportionally" to "equally" in walk-distribution comment - Document that _unifiedWalkMs includes setupVisitors overhead and overlaps with per-phase timers (not an additive bucket) - Add JSDoc to _unifiedWalkMs field in AnalysisTiming interface
|
All three Greptile findings addressed in fa5e686:
|
Summary
walkWithVisitors) did all compute work upfront but its time was stored in a hidden_unifiedWalkMsfield, never attributed to individual phase timersdelegateToBuildFunctionsthen overwrote phase timers with just the near-zero DB-write timeChanges
walkWithVisitorscall and distribute proportionally among active visitors (timing.astMs += share)delegateToBuildFunctionsfromtiming.xxxMs = ...totiming.xxxMs += ...so DB-write time accumulates on top of walk timeTest plan
tsc --noEmitpassesbiome checkclean on changed filetests/builder/pipeline.test.ts— 4/4 passtests/integration/build.test.ts— 17/17 pass (2 skipped, 1 pre-existing WASM grammar failure in worktree)