The SetTag function takes an interface{}, so every string argument
must be converted using the convTString internal functions, which
allocates a wrapper. Since this is an internal function, we can use
setMeta directly. This seems to be what happens elsewhere in this
function. These are the only two uses of SetTag. This removes up to
2 memory allocations on each call to this function.
contrib/.../grpc: Add benchmark for env and version tags, and for the
NoDebugStack() option. This should more accurately represent how the
gRPC interceptor is typically configured. The benchstat output from
my laptop for 10 runs shows this change saves about 1-2% CPU, and
the expected 1 allocation for the env tag, because the version tag is
not set on the gRPC interceptor spans.
name old time/op new time/op delta
UnaryServerInterceptor/ok_no_metadata-8 4.14µs ± 4% 4.11µs ±14% ~ (p=0.190 n=10+10)
UnaryServerInterceptor/ok_with_metadata_no_parent-8 4.87µs ± 3% 4.77µs ± 3% -1.96% (p=0.011 n=9+9)
UnaryServerInterceptor/ok_with_metadata_with_parent-8 4.29µs ± 3% 4.18µs ± 1% -2.50% (p=0.000 n=10+9)
UnaryServerInterceptor/ok_no_metadata_with_analytics_rate-8 4.25µs ± 4% 4.13µs ± 1% -2.76% (p=0.002 n=10+9)
UnaryServerInterceptor/error_no_metadata-8 10.6µs ± 3% 10.5µs ± 3% ~ (p=0.113 n=10+9)
UnaryServerInterceptor/error_no_metadata_no_stack-8 5.24µs ± 2% 5.15µs ± 4% ~ (p=0.051 n=10+9)
name old alloc/op new alloc/op delta
UnaryServerInterceptor/ok_no_metadata-8 4.25kB ± 0% 4.23kB ± 0% -0.38% (p=0.001 n=10+10)
UnaryServerInterceptor/ok_with_metadata_no_parent-8 4.86kB ± 0% 4.84kB ± 1% -0.42% (p=0.001 n=7+10)
UnaryServerInterceptor/ok_with_metadata_with_parent-8 3.96kB ± 0% 3.95kB ± 0% -0.28% (p=0.017 n=10+10)
UnaryServerInterceptor/ok_no_metadata_with_analytics_rate-8 4.45kB ± 0% 4.44kB ± 0% ~ (p=0.055 n=10+9)
UnaryServerInterceptor/error_no_metadata-8 10.6kB ± 0% 10.6kB ± 0% -0.32% (p=0.001 n=10+9)
UnaryServerInterceptor/error_no_metadata_no_stack-8 5.56kB ± 0% 5.54kB ± 1% -0.41% (p=0.007 n=10+10)
name old allocs/op new allocs/op delta
UnaryServerInterceptor/ok_no_metadata-8 43.0 ± 0% 42.0 ± 0% -2.33% (p=0.000 n=10+10)
UnaryServerInterceptor/ok_with_metadata_no_parent-8 48.0 ± 0% 47.0 ± 0% -2.08% (p=0.000 n=10+10)
UnaryServerInterceptor/ok_with_metadata_with_parent-8 39.0 ± 0% 38.0 ± 0% -2.56% (p=0.000 n=10+10)
UnaryServerInterceptor/ok_no_metadata_with_analytics_rate-8 45.0 ± 0% 44.0 ± 0% -2.22% (p=0.000 n=10+10)
UnaryServerInterceptor/error_no_metadata-8 60.0 ± 0% 59.0 ± 0% -1.67% (p=0.000 n=10+10)
UnaryServerInterceptor/error_no_metadata_no_stack-8 47.0 ± 0% 46.0 ± 0% -2.13% (p=0.000 n=10+10)