Skip to content

Commit

Permalink
Avoid extra allocations (#2449)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan authored Feb 9, 2021
1 parent 90ccbfa commit 8b3d87a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions processor/batchprocessor/splittraces.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ func splitTrace(size int, toSplit pdata.Traces) pdata.Traces {
copiedSpans := 0
result := pdata.NewTraces()
rss := toSplit.ResourceSpans()
result.ResourceSpans().Resize(rss.Len())
rssCount := 0
for i := rss.Len() - 1; i >= 0; i-- {
rssCount++
rs := rss.At(i)
destRs := pdata.NewResourceSpans()
destRs := result.ResourceSpans().At(result.ResourceSpans().Len() - 1 - i)
rs.Resource().CopyTo(destRs.Resource())
result.ResourceSpans().Append(destRs)

for j := rs.InstrumentationLibrarySpans().Len() - 1; j >= 0; j-- {
instSpans := rs.InstrumentationLibrarySpans().At(j)
Expand All @@ -54,12 +56,14 @@ func splitTrace(size int, toSplit pdata.Traces) pdata.Traces {
rs.InstrumentationLibrarySpans().Resize(rs.InstrumentationLibrarySpans().Len() - 1)
}
if copiedSpans == size {
result.ResourceSpans().Resize(rssCount)
return result
}
}
if rs.InstrumentationLibrarySpans().Len() == 0 {
rss.Resize(rss.Len() - 1)
}
}
result.ResourceSpans().Resize(rssCount)
return result
}

0 comments on commit 8b3d87a

Please sign in to comment.