Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddtrace/tracer.Measured(): Cache a global instance (save 1 alloc/call) #1184

Merged
merged 2 commits into from Mar 8, 2022

Conversation

evanj
Copy link
Contributor

@evanj evanj commented Feb 28, 2022

This saves one allocation for every call to this function. This
function is called in about 26 places in contrib/..., which includes
some fairly hot code paths, such as in the gRPC interceptors. The
gRPC interceptor microbenchmark shows this saves about ~8% CPU, and
reduces one allocation per call. This is part of my attempt to reduce
the overhead of gRPC tracing.

name                                                         old time/op    new time/op    delta
UnaryServerInterceptor/ok_no_metadata-8                        5.33µs ± 8%    4.94µs ± 5%   -7.17%  (p=0.002 n=9+10)
UnaryServerInterceptor/ok_with_metadata_no_parent-8            6.44µs ± 7%    5.79µs ± 3%  -10.19%  (p=0.000 n=9+9)
UnaryServerInterceptor/ok_with_metadata_with_parent-8          5.52µs ± 9%    5.05µs ± 3%   -8.47%  (p=0.000 n=10+9)
UnaryServerInterceptor/ok_no_metadata_with_analytics_rate-8    5.61µs ±10%    5.15µs ± 3%   -8.06%  (p=0.007 n=10+10)
UnaryServerInterceptor/error_no_metadata-8                     13.3µs ±15%    11.7µs ± 0%  -12.16%  (p=0.007 n=10+6)

name                                                         old alloc/op   new alloc/op   delta
UnaryServerInterceptor/ok_no_metadata-8                        4.94kB ± 0%    4.89kB ± 0%   -1.00%  (p=0.000 n=9+9)
UnaryServerInterceptor/ok_with_metadata_no_parent-8            5.57kB ± 1%    5.52kB ± 0%   -0.88%  (p=0.000 n=10+9)
UnaryServerInterceptor/ok_with_metadata_with_parent-8          4.66kB ± 0%    4.62kB ± 0%   -0.97%  (p=0.000 n=10+9)
UnaryServerInterceptor/ok_no_metadata_with_analytics_rate-8    5.14kB ± 0%    5.09kB ± 1%   -0.94%  (p=0.000 n=10+10)
UnaryServerInterceptor/error_no_metadata-8                     11.3kB ± 0%    11.2kB ± 0%   -0.33%  (p=0.004 n=10+10)

name                                                         old allocs/op  new allocs/op  delta
UnaryServerInterceptor/ok_no_metadata-8                          52.0 ± 0%      51.0 ± 0%   -1.92%  (p=0.000 n=10+10)
UnaryServerInterceptor/ok_with_metadata_no_parent-8              57.0 ± 0%      56.0 ± 0%   -1.75%  (p=0.000 n=10+10)
UnaryServerInterceptor/ok_with_metadata_with_parent-8            48.0 ± 0%      47.0 ± 0%   -2.08%  (p=0.000 n=10+10)
UnaryServerInterceptor/ok_no_metadata_with_analytics_rate-8      54.0 ± 0%      53.0 ± 0%   -1.85%  (p=0.000 n=10+10)
UnaryServerInterceptor/error_no_metadata-8                       69.0 ± 0%      68.0 ± 0%   -1.45%  (p=0.000 n=10+10)

This saves one allocation for every call to this function. This
function is called in about 26 places in contrib/..., which includes
some fairly hot code paths, such as in the gRPC interceptors. The
gRPC interceptor microbenchmark shows this saves about ~8% CPU, and
reduces one allocation per call. This is part of my attempt to reduce
the overhead of gRPC tracing.

name                                                         old time/op    new time/op    delta
UnaryServerInterceptor/ok_no_metadata-8                        5.33µs ± 8%    4.94µs ± 5%   -7.17%  (p=0.002 n=9+10)
UnaryServerInterceptor/ok_with_metadata_no_parent-8            6.44µs ± 7%    5.79µs ± 3%  -10.19%  (p=0.000 n=9+9)
UnaryServerInterceptor/ok_with_metadata_with_parent-8          5.52µs ± 9%    5.05µs ± 3%   -8.47%  (p=0.000 n=10+9)
UnaryServerInterceptor/ok_no_metadata_with_analytics_rate-8    5.61µs ±10%    5.15µs ± 3%   -8.06%  (p=0.007 n=10+10)
UnaryServerInterceptor/error_no_metadata-8                     13.3µs ±15%    11.7µs ± 0%  -12.16%  (p=0.007 n=10+6)

name                                                         old alloc/op   new alloc/op   delta
UnaryServerInterceptor/ok_no_metadata-8                        4.94kB ± 0%    4.89kB ± 0%   -1.00%  (p=0.000 n=9+9)
UnaryServerInterceptor/ok_with_metadata_no_parent-8            5.57kB ± 1%    5.52kB ± 0%   -0.88%  (p=0.000 n=10+9)
UnaryServerInterceptor/ok_with_metadata_with_parent-8          4.66kB ± 0%    4.62kB ± 0%   -0.97%  (p=0.000 n=10+9)
UnaryServerInterceptor/ok_no_metadata_with_analytics_rate-8    5.14kB ± 0%    5.09kB ± 1%   -0.94%  (p=0.000 n=10+10)
UnaryServerInterceptor/error_no_metadata-8                     11.3kB ± 0%    11.2kB ± 0%   -0.33%  (p=0.004 n=10+10)

name                                                         old allocs/op  new allocs/op  delta
UnaryServerInterceptor/ok_no_metadata-8                          52.0 ± 0%      51.0 ± 0%   -1.92%  (p=0.000 n=10+10)
UnaryServerInterceptor/ok_with_metadata_no_parent-8              57.0 ± 0%      56.0 ± 0%   -1.75%  (p=0.000 n=10+10)
UnaryServerInterceptor/ok_with_metadata_with_parent-8            48.0 ± 0%      47.0 ± 0%   -2.08%  (p=0.000 n=10+10)
UnaryServerInterceptor/ok_no_metadata_with_analytics_rate-8      54.0 ± 0%      53.0 ± 0%   -1.85%  (p=0.000 n=10+10)
UnaryServerInterceptor/error_no_metadata-8                       69.0 ± 0%      68.0 ± 0%   -1.45%  (p=0.000 n=10+10)
@evanj evanj requested a review from a team February 28, 2022 14:18
@Julio-Guerra Julio-Guerra added this to the 1.37.0 milestone Mar 8, 2022
@Julio-Guerra Julio-Guerra merged commit 7d066c1 into v1 Mar 8, 2022
@Julio-Guerra Julio-Guerra deleted the evan.jones/tracer-measured-cache branch March 8, 2022 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants