Skip to content
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

ColStr.Append has performance problem #1164

Open
hongker opened this issue Dec 21, 2023 · 5 comments
Open

ColStr.Append has performance problem #1164

hongker opened this issue Dec 21, 2023 · 5 comments

Comments

@hongker
Copy link
Contributor

hongker commented Dec 21, 2023

insert 100k records by Batch.Append function, I found it's has performance problem, current code is:

// code position: proto/col_str.go(23)
// Append string to column.
func (c *ColStr) Append(v string) {
	start := len(c.Buf)
	c.Buf = append(c.Buf, v...)
	end := len(c.Buf)
	c.Pos = append(c.Pos, Position{Start: start, End: end})
}

the cap of c.Buf not pre define, so it will took much time on runtime.growslice when insert too many records,

// pprof result: 
----------------------------------------------------------+-------------
                                            31.40s   100% |   github.com/ClickHouse/clickhouse-go/v2/lib/column.(*String).AppendRow
     2.34s  0.72%  5.27%     31.40s  9.72%                | github.com/ClickHouse/ch-go/proto.(*ColStr).Append
                                            22.94s 73.06% |   runtime.growslice
                                             5.82s 18.54% |   runtime.memmove
                                             0.27s  0.86% |   runtime.gcWriteBarrierR8
                                             0.02s 0.064% |   runtime.asyncPreempt
                                             0.01s 0.032% |   runtime.gcWriteBarrier
----------------------------------------------------------+-------------

Describe the solution you'd like
I want a function, it can pre define the cap of col.Buf, like this:

func (c *ColStr) WithBufCap(cap int) {
        c.Buf = make([]byte, 0, cap)
}
@jkaflik
Copy link
Contributor

jkaflik commented Dec 27, 2023

Hi @hongker
would you mind submitting a proposal PR?

@kevinmingtarja
Copy link

Hi, I'd like to contribute a PR if no-one is working on this.

@jkaflik
Copy link
Contributor

jkaflik commented Jan 15, 2024

@kevinmingtarja go ahead. Contributions are appreciated.

@hongker
Copy link
Contributor Author

hongker commented Jan 16, 2024

Hi, I'd like to contribute a PR if no-one is working on this.

did you finished this work?

@kevinmingtarja
Copy link

Hi @hongker, no I just started. But if you want to do it, please go ahead since you are the one who proposed the feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants