perf: add parallel processing to ListChanges and ListSpecs#367
perf: add parallel processing to ListChanges and ListSpecs#367connerohnesorge wants to merge 1 commit intomainfrom
Conversation
Optimize spectr list startup performance by processing changes and specs concurrently using goroutines. This reduces the O(m × n) sequential file I/O bottleneck to parallel processing, providing linear speedup on multi-core systems. Changes: - Process each change/spec in parallel goroutines - Extract processChange() and processSpec() helper methods - Maintain original ordering using indexed results - Fix lint violations (use nil instead of empty slices) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
WalkthroughChanges introduce parallel processing to ListChanges and ListSpecs functions using worker pools. Adds unexported helper functions processChange and processSpec for single-item processing, concurrent result collection via channels, and preserves original input ordering in returned slices. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant ListChanges/ListSpecs
participant Discovery
participant WorkerPool
participant Parsers
participant ResultCollector
Caller->>ListChanges/ListSpecs: ListChanges/ListSpecs()
ListChanges/ListSpecs->>Discovery: GetActiveChanges/GetSpecs(projectPath)
Discovery-->>ListChanges/ListSpecs: IDs []string
Note over ListChanges/ListSpecs: Create WaitGroup<br/>& results channel
par Parallel Processing
loop For each ID
ListChanges/ListSpecs->>WorkerPool: processChange/processSpec(ID, index)
WorkerPool->>Parsers: ExtractTitle()<br/>CountDeltas/Tasks/Requirements()
Parsers-->>WorkerPool: computed values
WorkerPool->>ResultCollector: send result{ID, index, info}
end
end
ResultCollector->>ListChanges/ListSpecs: all results collected
ListChanges/ListSpecs->>ListChanges/ListSpecs: sort by original index
ListChanges/ListSpecs-->>Caller: ordered slice of Info
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Important Action Needed: IP Allowlist UpdateIf your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:
Failure to add the new IP will result in interrupted reviews. 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 |
Summary
Optimizes
spectr list -Istartup performance by adding parallel processing to change and spec listing operations.Before: Sequential file I/O for each change/spec (O(m × n) complexity)
After: Concurrent goroutine processing (linear speedup on multi-core systems)
Changes
ListChanges()andListSpecs()using goroutines and channelsprocessChange()andprocessSpec()helper methods to reduce function complexitynilinstead of empty slices)Performance Impact
In repos with many changes, this provides immediate speedup:
Testing
go test ./...)go test -race ./internal/list/...)nix develop -c lint)🤖 Generated with Claude Code
Summary by CodeRabbit