Skip to content

Commit 5eacdab

Browse files
committed
[pdata/pprofile] Keep merge index construction out of the timed benchmark section
The per-entity switchDictionary benchmarks built the merge index inside the timed section, so they measured index construction rather than the merge, and were not comparable against the pre-index implementation. Where the destination is rebuilt each iteration, the index is now built alongside it under the existing StopTimer. Where the destination is built once and accumulates across iterations (scope profiles, sample), the index hoists out of the loop entirely, matching how MergeTo uses it.
1 parent 2c9d5f0 commit 5eacdab

11 files changed

Lines changed: 23 additions & 11 deletions

pdata/pprofile/function_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,10 @@ func BenchmarkFunctionSwitchDictionary(b *testing.B) {
339339
b.StopTimer()
340340
dst := NewProfilesDictionary()
341341
dst.StringTable().Append("", "foo")
342+
mi := newMergeIndex(dst)
342343
b.StartTimer()
343344

344-
_ = fn.switchDictionary(src, dst, newMergeIndex(dst))
345+
_ = fn.switchDictionary(src, dst, mi)
345346
}
346347
}
347348

pdata/pprofile/keyvalueandunit_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ func BenchmarkKeyValueAndUnitSwitchDictionary(b *testing.B) {
260260
for b.Loop() {
261261
b.StopTimer()
262262
dst := NewProfilesDictionary()
263+
mi := newMergeIndex(dst)
263264
b.StartTimer()
264265

265-
_ = kvu.switchDictionary(src, dst, newMergeIndex(dst))
266+
_ = kvu.switchDictionary(src, dst, mi)
266267
}
267268
}
268269

pdata/pprofile/line_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,10 @@ func BenchmarkLineSwitchDictionary(b *testing.B) {
265265
for b.Loop() {
266266
b.StopTimer()
267267
dst := NewProfilesDictionary()
268+
mi := newMergeIndex(dst)
268269
b.StartTimer()
269270

270-
_ = l.switchDictionary(src, dst, newMergeIndex(dst))
271+
_ = l.switchDictionary(src, dst, mi)
271272
}
272273
}
273274

pdata/pprofile/location_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,10 @@ func BenchmarkLocationSwitchDictionary(b *testing.B) {
343343
dst.StringTable().Append("", "foo")
344344
dst.AttributeTable().AppendEmpty()
345345
dst.AttributeTable().AppendEmpty().SetKeyStrindex(1)
346+
mi := newMergeIndex(dst)
346347
b.StartTimer()
347348

348-
_ = l.switchDictionary(src, dst, newMergeIndex(dst))
349+
_ = l.switchDictionary(src, dst, mi)
349350
}
350351
}
351352

pdata/pprofile/mapping_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,10 @@ func BenchmarkMappingSwitchDictionary(b *testing.B) {
292292
dst.StringTable().Append("", "foo")
293293
dst.AttributeTable().AppendEmpty()
294294
dst.AttributeTable().AppendEmpty().SetKeyStrindex(1)
295+
mi := newMergeIndex(dst)
295296
b.StartTimer()
296297

297-
_ = m.switchDictionary(src, dst, newMergeIndex(dst))
298+
_ = m.switchDictionary(src, dst, mi)
298299
}
299300
}
300301

pdata/pprofile/profile_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,10 @@ func BenchmarkProfileSwitchDictionary(b *testing.B) {
351351
dst.StringTable().Append("", "foo")
352352
dst.AttributeTable().AppendEmpty()
353353
dst.AttributeTable().AppendEmpty().SetKeyStrindex(1)
354+
mi := newMergeIndex(dst)
354355
b.StartTimer()
355356

356-
_ = p.switchDictionary(src, dst, newMergeIndex(dst))
357+
_ = p.switchDictionary(src, dst, mi)
357358
}
358359
}
359360

pdata/pprofile/resourceprofiles_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ func BenchmarkResourceProfilesSwitchDictionary(b *testing.B) {
107107
for b.Loop() {
108108
b.StopTimer()
109109
dst := NewProfilesDictionary()
110+
mi := newMergeIndex(dst)
110111
b.StartTimer()
111112

112-
_ = r.switchDictionary(src, dst, newMergeIndex(dst))
113+
_ = r.switchDictionary(src, dst, mi)
113114
}
114115
}

pdata/pprofile/sample_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,11 @@ func BenchmarkSampleSwitchDictionary(b *testing.B) {
330330
src.LinkTable().AppendEmpty()
331331
src.LinkTable().AppendEmpty().SetSpanID(pcommon.SpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8}))
332332

333+
mi := newMergeIndex(dst)
334+
333335
b.ReportAllocs()
334336

335337
for b.Loop() {
336-
_ = s.switchDictionary(src, dst, newMergeIndex(dst))
338+
_ = s.switchDictionary(src, dst, mi)
337339
}
338340
}

pdata/pprofile/scopeprofiles_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ func BenchmarkScopeProfilesSwitchDictionary(b *testing.B) {
103103
src.LinkTable().AppendEmpty().SetSpanID(pcommon.SpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8}))
104104

105105
dst := NewProfilesDictionary()
106+
mi := newMergeIndex(dst)
106107

107108
b.ReportAllocs()
108109

109110
for b.Loop() {
110-
_ = s.switchDictionary(src, dst, newMergeIndex(dst))
111+
_ = s.switchDictionary(src, dst, mi)
111112
}
112113
}

pdata/pprofile/stack_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ func BenchmarkStackSwitchDictionary(b *testing.B) {
241241
dst := NewProfilesDictionary()
242242
dst.LocationTable().AppendEmpty()
243243
dst.LocationTable().AppendEmpty().SetAddress(43)
244+
mi := newMergeIndex(dst)
244245
b.StartTimer()
245246

246-
_ = s.switchDictionary(src, dst, newMergeIndex(dst))
247+
_ = s.switchDictionary(src, dst, mi)
247248
}
248249
}

0 commit comments

Comments
 (0)