finishWithError needs to allocate a []tracer.FinishOption slice to
pass arguments to span.Finish. However, those arguments are only used
if err != nil. Only allocate the slice if it is used. Allocate the
exactly right size of slice. This appears to remove 3 allocations in
the "no error" case, and 1 allocation if the NoDebugStack() option is
specified. In the case of an error, there is no difference. This may
also make a small difference in the run time. The benchstat results
from my Mac laptop are below.
name old time/op new time/op delta
UnaryServerInterceptor/ok_no_metadata-8 5.33µs ± 8% 4.73µs ± 5% -11.27% (p=0.000 n=9+9)
UnaryServerInterceptor/ok_with_metadata_no_parent-8 6.44µs ± 7% 5.71µs ±13% -11.41% (p=0.001 n=9+10)
UnaryServerInterceptor/ok_with_metadata_with_parent-8 5.52µs ± 9% 5.03µs ± 8% -8.94% (p=0.002 n=10+9)
UnaryServerInterceptor/ok_no_metadata_with_analytics_rate-8 5.61µs ±10% 4.94µs ± 3% -11.89% (p=0.000 n=10+10)
UnaryServerInterceptor/error_no_metadata-8 13.3µs ±15% 11.6µs ± 1% -12.90% (p=0.005 n=10+7)
name old alloc/op new alloc/op delta
UnaryServerInterceptor/ok_no_metadata-8 4.94kB ± 0% 4.85kB ± 0% -1.87% (p=0.000 n=9+7)
UnaryServerInterceptor/ok_with_metadata_no_parent-8 5.57kB ± 1% 5.46kB ± 0% -1.91% (p=0.000 n=10+10)
UnaryServerInterceptor/ok_with_metadata_with_parent-8 4.66kB ± 0% 4.57kB ± 0% -2.05% (p=0.000 n=10+10)
UnaryServerInterceptor/ok_no_metadata_with_analytics_rate-8 5.14kB ± 0% 5.05kB ± 1% -1.78% (p=0.000 n=10+10)
UnaryServerInterceptor/error_no_metadata-8 11.3kB ± 0% 11.3kB ± 0% ~ (p=0.066 n=10+8)
name old allocs/op new allocs/op delta
UnaryServerInterceptor/ok_no_metadata-8 52.0 ± 0% 49.0 ± 0% -5.77% (p=0.000 n=10+10)
UnaryServerInterceptor/ok_with_metadata_no_parent-8 57.0 ± 0% 54.0 ± 0% -5.26% (p=0.000 n=10+10)
UnaryServerInterceptor/ok_with_metadata_with_parent-8 48.0 ± 0% 45.0 ± 0% -6.25% (p=0.000 n=10+10)
UnaryServerInterceptor/ok_no_metadata_with_analytics_rate-8 54.0 ± 0% 51.0 ± 0% -5.56% (p=0.000 n=10+10)
UnaryServerInterceptor/error_no_metadata-8 69.0 ± 0% 69.0 ± 0% ~ (all equal)