Skip to content

Commit bcb4af2

Browse files
authored
Compare *stacktraceTree.insert against different initial sizes (#4033)
* Use default size constant for initializing tree in benchmark Refactor the benchmark for `*stacktraceTree.insert` to use the constant for default tree size instead of hard-coding 0. This will become useful in future changes. * Add benchmark for `*stacktraceTree.insert` with different init sizes This benchmark can be slow, thus it won't run unless the `COMPARE_STACKTRACETREE_INSERT_DEFAULT_SIZES` environment variable is set to true. In addition, if the `-v` flag is passed to `go test` it will print the initial and max tree size after inserting all the samples from the test profile. * Remove commented out line * Always run stacktraceTree default size benchmark * Use b.ReportMetric instead of b.Log We could revisit if we want to always show these values, and if we want to add/remove columns.
1 parent 61f51d4 commit bcb4af2

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

pkg/phlaredb/symdb/stacktrace_tree_test.go

+29-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package symdb
33
import (
44
"bytes"
55
"math/rand"
6+
"strconv"
67
"testing"
78

89
"github.com/stretchr/testify/assert"
@@ -220,9 +221,36 @@ func Benchmark_stacktrace_tree_insert(b *testing.B) {
220221
b.ReportAllocs()
221222

222223
for i := 0; i < b.N; i++ {
223-
x := newStacktraceTree(0)
224+
x := newStacktraceTree(defaultStacktraceTreeSize)
224225
for j := range p.Sample {
225226
x.insert(p.Sample[j].LocationId)
226227
}
227228
}
228229
}
230+
231+
func Benchmark_stacktrace_tree_insert_default_sizes(b *testing.B) {
232+
p, err := pprof.OpenFile("testdata/profile.pb.gz")
233+
require.NoError(b, err)
234+
235+
b.ResetTimer()
236+
237+
for _, size := range []int{0, 10, 1024, 2048, 4096, 8192} {
238+
b.Run("size="+strconv.Itoa(size), func(b *testing.B) {
239+
b.ReportAllocs()
240+
241+
for i := 0; i < b.N; i++ {
242+
x := newStacktraceTree(size)
243+
for j := range p.Sample {
244+
x.insert(p.Sample[j].LocationId)
245+
}
246+
247+
if testing.Verbose() {
248+
c := float64(cap(x.nodes))
249+
b.ReportMetric(c, "cap")
250+
b.ReportMetric(c*float64(stacktraceTreeNodeSize), "size")
251+
b.ReportMetric(float64(x.len())/float64(c)*100, "fill")
252+
}
253+
}
254+
})
255+
}
256+
}

0 commit comments

Comments
 (0)