ClickHouse / ClickHouse/ch-go

High CPU from append: frequent runtime.growslice due to missing slice preallocation

Open
#1,100 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
428
Forks
84
Avg merge
9d 6h
Merged PRs (30d)
4

Description

## Describe the bug
- The `Append` built-in uses excessive CPU due to frequent runtime.growslice calls.

Image

## Steps to reproduce
1. Run an INSERT that writes a large number of rows.
2. This triggers multiple append operations that allocate new underlying arrays because the current slice has no predefined capacity.
3. Capture a Go CPU profile and inspect the hot spots for append and runtime.growslice.

## Expected behavior
- Provide a way to preallocate slice capacity (or otherwise reduce allocations) so that calls to runtime.growslice are minimized or eliminated.

## Code example
- The current column type does not allow setting the initial capacity of the slice:
```go
type ColDateTime64 struct {
Data []DateTime64
Location *time.Location
Precision Precision
PrecisionSet bool
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the ColDateTime64 type shown in the issue and trace how its Data slice is populated during large INSERT operations. Use a Go CPU profile to confirm runtime.growslice activity, then define and implement a capacity-preallocation approach that reduces those allocations and verify the profiling result.

Written by the indexing model from the issue text.

Assessment

Tech stack
clickhouse, go
Domain
database, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.