diff --git a/stats/benchmark_test.go b/stats/benchmark_test.go index e784b8c4c..fade54f9a 100644 --- a/stats/benchmark_test.go +++ b/stats/benchmark_test.go @@ -109,5 +109,13 @@ func BenchmarkRecord8_8Tags(b *testing.B) { } func makeMeasure() *stats.Int64Measure { - return stats.Int64("m", "test measure", "") + m := stats.Int64("m", "test measure", "") + v := &view.View{ + Measure: m, + Aggregation: view.Sum(), + } + if err := view.Register(v); err != nil { + panic(err.Error()) + } + return m } diff --git a/stats/record.go b/stats/record.go index 2b9728346..f8a52bcd9 100644 --- a/stats/record.go +++ b/stats/record.go @@ -89,7 +89,24 @@ func createRecordOption(ros ...Options) *recordOptions { // Record records one or multiple measurements with the same context at once. // If there are any tags in the context, measurements will be tagged with them. func Record(ctx context.Context, ms ...Measurement) { - RecordWithOptions(ctx, WithMeasurements(ms...)) + // Record behaves the same as RecordWithOptions, but because we do not have to handle generic functionality + // (RecordOptions) we can reduce some allocations to speed up this hot path + if len(ms) == 0 { + return + } + recorder := internal.DefaultRecorder + record := false + for _, m := range ms { + if m.desc.subscribed() { + record = true + break + } + } + if !record { + return + } + recorder(tag.FromContext(ctx), ms, nil) + return } // RecordWithTags records one or multiple measurements at once.