-
Notifications
You must be signed in to change notification settings - Fork 4
perf: add streaming iterator API for memory-efficient result processing #619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add RowIterator[T] type that provides streaming access to query results without materializing the entire result slice upfront. This is useful for: - Memory-efficient processing of large result sets - Early termination when a specific item is found - Chained processing pipelines The iterator includes: - Next()/Value()/Err() for standard iteration - Collect() to materialize remaining results when needed - Close() to release database resources - NextPageToken() for pagination Refactor listConnectorObjects to use the streaming API internally, reducing code duplication and ensuring consistent behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
WalkthroughThe changes introduce a generic Changes
Sequence DiagramsequenceDiagram
participant Caller
participant listConnectorObjects
participant streamConnectorObjects
participant rowIterator
participant Database
Caller->>listConnectorObjects: Call with request
listConnectorObjects->>streamConnectorObjects: Call with context, table, factory
streamConnectorObjects->>Database: Execute query
streamConnectorObjects-->>listConnectorObjects: Return *rowIterator[T]
Note over listConnectorObjects: Defer Close()
listConnectorObjects->>rowIterator: Collect()
loop For each row
rowIterator->>Database: Fetch next row
rowIterator->>rowIterator: Unmarshal & check errors
Note over rowIterator: Next() returns true,<br/>Value() returns T
end
rowIterator-->>listConnectorObjects: Return ([]T, error)
listConnectorObjects->>rowIterator: Close()
listConnectorObjects-->>Caller: Return ([]T, nextPageToken, error)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: Repository UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (1)pkg/dotc1z/sql_helpers.go (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (7)
Comment |
Summary
rowIterator[T]type for streaming access to query results without materializing the entire result slicestreamConnectorObjects()function that returns the iteratorlistConnectorObjects()to use the streaming API internally, reducing code duplicationListSyncRuns()based on pageSizeThe iterator provides:
Next()/Value()/Err()for standard iteration patternCollect()to materialize remaining results when a slice is neededClose()to release database resourcesNextPageToken()for paginationThis is useful for:
Context
Profile analysis of
temporal_syncshowedgo-sqlite.(*conn).columnTextallocating ~914 MB/sec. While the root cause is in the driver, application-level optimizations provide defense in depth and reduce peak memory usage.Test plan
listConnectorObjectsbehavior unchanged (uses iterator internally)🤖 Generated with Claude Code
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.