-
Notifications
You must be signed in to change notification settings - Fork 7
Optimize ClickHouse uploader hot path #970
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes the ClickHouse uploader hot path by caching per-column converters alongside each Schema and reusing a preallocated row buffer to eliminate per-row allocations during the inner ingest loop.
Key changes:
- Cache value converters per Schema to avoid repeated type-switch overhead
- Use preallocated row buffer and
convertRecordIntohelper to reduce allocations - Add benchmark test to track performance regressions
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| storage/store_test.go | Add cleanup to prevent resource leaks in test |
| ingestor/clickhouse/uploader_bench_test.go | New benchmark test for measuring hot path performance |
| ingestor/clickhouse/uploader.go | Optimize record processing with cached converters and buffer reuse |
| ingestor/clickhouse/schema.go | Add converter caching and new convertRecordInto function |
| cmd/collector/config/config_test.go | Fix test case interval value |
| cmd/collector/config/config.go | Simplify WAL flush interval validation |
| func buildConverters(columns []Column) []valueConverter { | ||
| converters := make([]valueConverter, len(columns)) | ||
| for i, column := range columns { | ||
| column := column |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable shadowing pattern is used to capture the loop variable for the closure. Consider using a more explicit pattern like columnName := column.Name and referencing it directly in the error message to make the intent clearer.
Copilot uses AI. Check for mistakes.
| c.WALFlushIntervalMilliSeconds = DefaultConfig.WALFlushIntervalMilliSeconds | ||
| } else if c.WALFlushIntervalMilliSeconds < 0 { | ||
| if c.WALFlushIntervalMilliSeconds < 0 { | ||
| return errors.New("wal-flush-interval must be greater than 0") |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message says 'must be greater than 0' but the condition allows 0 (only checks < 0). The message should be 'must be greater than or equal to 0' to match the actual validation logic.
| return errors.New("wal-flush-interval must be greater than 0") | |
| return errors.New("wal-flush-interval must be greater than or equal to 0") |
Copilot uses AI. Check for mistakes.
| interval: 100, | ||
| wantErr: false, | ||
| }, | ||
| { |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case change from 100 to 0 should include a comment explaining why zero is now a valid interval value, especially since this appears to be testing a boundary condition.
| { | |
| { | |
| // Zero is now considered a valid WAL flush interval value, meaning "no periodic flush". |
Copilot uses AI. Check for mistakes.
Summary
reuse a preallocated []any row buffer and pipe batches through the new
convertRecordIntohelper to eliminate per-row allocationsBenchmarkProcessRecordsto track hot-path regressions moving forwardBenchmarks
Tests
go test ./ingestor/clickhousego test -bench=ProcessRecords -benchmem ./ingestor/clickhouse