Skip to content

Commit

Permalink
remove bytes copy for last sample sent
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyassrivatsan committed Jul 7, 2020
1 parent 6a75efb commit 3591d5d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/cmd/services/m3coordinator/downsample/metrics_appender.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (a *metricsAppender) newSamplesAppenders(
sm := stagedMetadata
sm.Pipelines = []metadata.PipelineMetadata{pipeline}

appender, err := a.newSamplesAppender(tags, sm)
appender, err := a.newSamplesAppender(tags, sm, true)
if err != nil {
return []samplesAppender{}, err
}
Expand All @@ -372,7 +372,7 @@ func (a *metricsAppender) newSamplesAppenders(

sm := stagedMetadata
sm.Pipelines = pipelines
appender, err := a.newSamplesAppender(a.tags, sm)
appender, err := a.newSamplesAppender(a.tags, sm, false)
if err != nil {
return []samplesAppender{}, err
}
Expand All @@ -382,6 +382,7 @@ func (a *metricsAppender) newSamplesAppenders(
func (a *metricsAppender) newSamplesAppender(
tags *tags,
sm metadata.StagedMetadata,
copyID bool,
) (samplesAppender, error) {
a.tagEncoder.Reset()
if err := a.tagEncoder.Encode(tags); err != nil {
Expand All @@ -392,9 +393,14 @@ func (a *metricsAppender) newSamplesAppender(
return samplesAppender{}, fmt.Errorf("unable to encode tags: names=%v, values=%v", tags.names, tags.values)
}
// NB (@shreyas): if this is the last use of the tagEncoder we do not need
// this copy, but its hard to know and enforce that.
id := make([]byte, data.Len())
copy(id, data.Bytes())
// this copy. The caller tells us what to do here.
var id []byte
if copyID {
id = make([]byte, data.Len())
copy(id, data.Bytes())
} else {
id = data.Bytes()
}
return samplesAppender{
agg: a.agg,
clientRemote: a.clientRemote,
Expand Down

0 comments on commit 3591d5d

Please sign in to comment.