-
Notifications
You must be signed in to change notification settings - Fork 1k
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
tune slice append performance #850
Conversation
umm, I will check ci failure result |
for b.N larger than 1, your code will let tmp grow so it's slower. |
Agree it! I intend to reduce the overhead of slice growth |
ci jobs pass |
I mean your benchmark is not correct func BenchmarkAppend(b *testing.B) {
strs := []string{"a", "b", "c"}
tmp := make([]string, 0, len(strs))
b.ResetTimer()
for i := 0; i < b.N; i++ {
+ tmp = tmp[:0]
for _, str := range strs {
tmp = append(tmp, str)
}
}
}
|
You are right. I put slice intialization in the loop and find slice assignment gets just a little more performance than append. Because function parseSingleEvent could be called with high frequency in binlog parsing, I think it may be acceptable
|
If I try to make strs be a slice with a larger size, performance difference between assign and append will be larger too
|
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.
rest lgtm
I will check it later |
I have changed the code as suggestion |
I find some codes abount binlog, which is doing slices assignment or append could be simply changed, so that we can get some perfomance tuning.
Hope that it could help
some corresponding benchmark code may be as follow: