Skip to content

Commit

Permalink
Pre-define capacities for rollups and TLFs (#353)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?

- Similar to honeycombio/libhoney-go#197, profiling shows we spend a lot of time in github.com/honeycombio/beeline-go/trace.(*Span).send generating the map.

## Short description of the changes

- define the map capacity in advance before returning it.

a subsequent follow-up might be allowing passing a map in its entirety to github.com/honeycombio/libhoney-go.(*Event).AddField so that the map entries do not need to be added one at a time when merging the maps together.

Or, better yet, golang/go#56182 could prevent this problem by giving us a more sensible API for mass additions to a map.
  • Loading branch information
lizthegrey authored Oct 17, 2022
1 parent eeaf3ba commit 99bcf6a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (t *Trace) getTraceLevelFields() map[string]interface{} {
t.tlfLock.Lock()
defer t.tlfLock.Unlock()
// return a copy of trace level fields
retVals := make(map[string]interface{})
retVals := make(map[string]interface{}, len(t.traceLevelFields))
for k, v := range t.traceLevelFields {
retVals[k] = v
}
Expand All @@ -190,7 +190,7 @@ func (t *Trace) getTraceLevelFields() map[string]interface{} {
func (t *Trace) getRollupFields() map[string]interface{} {
t.rollupLock.Lock()
defer t.rollupLock.Unlock()
rollupFields := make(map[string]interface{})
rollupFields := make(map[string]interface{}, len(t.rollupFields))
for k, v := range t.rollupFields {
rollupFields[k] = v
}
Expand Down

0 comments on commit 99bcf6a

Please sign in to comment.