This repository was archived by the owner on Jul 31, 2023. It is now read-only.
Optimize Record() to avoid extra allocations #1267
Merged
dashpole merged 2 commits intocensus-instrumentation:masterfrom Sep 14, 2021
Merged
Optimize Record() to avoid extra allocations #1267dashpole merged 2 commits intocensus-instrumentation:masterfrom
Record() to avoid extra allocations #1267dashpole merged 2 commits intocensus-instrumentation:masterfrom
Conversation
howardjohn
added a commit
to howardjohn/opencensus-go
that referenced
this pull request
Sep 14, 2021
This is built upon census-instrumentation#1267; that one should likely merge first. I split this out as it has a small public API change (to work around circular imports) to avoid issues on the first PR. Benchmark relative to census-instrumentation#1267: ``` me old time/op new time/op delta Record0-6 1.74ns ± 4% 1.79ns ± 2% +2.85% (p=0.238 n=5+5) Record1-6 634ns ± 6% 542ns ± 9% -14.55% (p=0.008 n=5+5) Record8-6 1.21µs ± 5% 1.23µs ± 2% +1.97% (p=0.254 n=5+5) Record8_WithRecorder-6 777ns ± 5% 792ns ± 5% +1.97% (p=0.421 n=5+5) Record8_Parallel-6 1.26µs ±24% 1.22µs ± 2% ~ (p=0.690 n=5+5) Record8_8Tags-6 1.23µs ± 2% 1.25µs ± 3% ~ (p=0.651 n=5+5) name old alloc/op new alloc/op delta Record0-6 0.00B 0.00B ~ (all equal) Record1-6 120B ± 0% 96B ± 0% -20.00% (p=0.008 n=5+5) Record8-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_WithRecorder-6 424B ± 0% 424B ± 0% ~ (all equal) Record8_Parallel-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_8Tags-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Record0-6 0.00 0.00 ~ (all equal) Record1-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_WithRecorder-6 4.00 ± 0% 4.00 ± 0% ~ (all equal) Record8_Parallel-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_8Tags-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) ```
dashpole
approved these changes
Sep 14, 2021
Contributor
Author
|
#1270 fixes the build failure |
Currently, the metric we record is not registered. This hits the fast-path code of not actually recording the metric, so we miss out on detecting any performance to that main code path. This registers the metrics so we actually trigger `record`.
Currently, `Record()` re-uses code with `RecordWithOptions`. This always creates allocations for createRecordOption, which is not needed in this case - we only have measurements and not generic options. With a little code duplication, we can reduce these allocations. ``` name old time/op new time/op delta Record0-6 92.2ns ± 9% 1.7ns ± 4% -98.11% (p=0.008 n=5+5) Record1-6 665ns ± 5% 634ns ± 6% -4.57% (p=0.095 n=5+5) Record8-6 1.24µs ± 5% 1.21µs ± 5% -2.18% (p=0.206 n=5+5) Record8_WithRecorder-6 796ns ± 5% 777ns ± 5% -2.45% (p=0.222 n=5+5) Record8_Parallel-6 1.21µs ± 2% 1.26µs ±24% ~ (p=0.690 n=5+5) Record8_8Tags-6 1.23µs ± 4% 1.23µs ± 2% ~ (p=0.968 n=5+5) name old alloc/op new alloc/op delta Record0-6 80.0B ± 0% 0.0B -100.00% (p=0.008 n=5+5) Record1-6 200B ± 0% 120B ± 0% -40.00% (p=0.008 n=5+5) Record8-6 424B ± 0% 344B ± 0% -18.87% (p=0.008 n=5+5) Record8_WithRecorder-6 424B ± 0% 424B ± 0% ~ (all equal) Record8_Parallel-6 424B ± 0% 344B ± 0% -18.87% (p=0.008 n=5+5) Record8_8Tags-6 424B ± 0% 344B ± 0% -18.87% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Record0-6 1.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5) Record1-6 4.00 ± 0% 3.00 ± 0% -25.00% (p=0.008 n=5+5) Record8-6 4.00 ± 0% 3.00 ± 0% -25.00% (p=0.008 n=5+5) Record8_WithRecorder-6 4.00 ± 0% 4.00 ± 0% ~ (all equal) Record8_Parallel-6 4.00 ± 0% 3.00 ± 0% -25.00% (p=0.008 n=5+5) Record8_8Tags-6 4.00 ± 0% 3.00 ± 0% -25.00% (p=0.008 n=5+5) ```
9ef197d to
b395dd0
Compare
howardjohn
added a commit
to howardjohn/opencensus-go
that referenced
this pull request
Sep 14, 2021
This is built upon census-instrumentation#1267; that one should likely merge first. I split this out as it has a small public API change (to work around circular imports) to avoid issues on the first PR. Benchmark relative to census-instrumentation#1267: ``` me old time/op new time/op delta Record0-6 1.74ns ± 4% 1.79ns ± 2% +2.85% (p=0.238 n=5+5) Record1-6 634ns ± 6% 542ns ± 9% -14.55% (p=0.008 n=5+5) Record8-6 1.21µs ± 5% 1.23µs ± 2% +1.97% (p=0.254 n=5+5) Record8_WithRecorder-6 777ns ± 5% 792ns ± 5% +1.97% (p=0.421 n=5+5) Record8_Parallel-6 1.26µs ±24% 1.22µs ± 2% ~ (p=0.690 n=5+5) Record8_8Tags-6 1.23µs ± 2% 1.25µs ± 3% ~ (p=0.651 n=5+5) name old alloc/op new alloc/op delta Record0-6 0.00B 0.00B ~ (all equal) Record1-6 120B ± 0% 96B ± 0% -20.00% (p=0.008 n=5+5) Record8-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_WithRecorder-6 424B ± 0% 424B ± 0% ~ (all equal) Record8_Parallel-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_8Tags-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Record0-6 0.00 0.00 ~ (all equal) Record1-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_WithRecorder-6 4.00 ± 0% 4.00 ± 0% ~ (all equal) Record8_Parallel-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_8Tags-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) ```
howardjohn
added a commit
to howardjohn/opencensus-go
that referenced
this pull request
Sep 14, 2021
This is built upon census-instrumentation#1267; that one should likely merge first. I split this out as it has a small public API change (to work around circular imports) to avoid issues on the first PR. Benchmark relative to census-instrumentation#1267: ``` me old time/op new time/op delta Record0-6 1.74ns ± 4% 1.79ns ± 2% +2.85% (p=0.238 n=5+5) Record1-6 634ns ± 6% 542ns ± 9% -14.55% (p=0.008 n=5+5) Record8-6 1.21µs ± 5% 1.23µs ± 2% +1.97% (p=0.254 n=5+5) Record8_WithRecorder-6 777ns ± 5% 792ns ± 5% +1.97% (p=0.421 n=5+5) Record8_Parallel-6 1.26µs ±24% 1.22µs ± 2% ~ (p=0.690 n=5+5) Record8_8Tags-6 1.23µs ± 2% 1.25µs ± 3% ~ (p=0.651 n=5+5) name old alloc/op new alloc/op delta Record0-6 0.00B 0.00B ~ (all equal) Record1-6 120B ± 0% 96B ± 0% -20.00% (p=0.008 n=5+5) Record8-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_WithRecorder-6 424B ± 0% 424B ± 0% ~ (all equal) Record8_Parallel-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_8Tags-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Record0-6 0.00 0.00 ~ (all equal) Record1-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_WithRecorder-6 4.00 ± 0% 4.00 ± 0% ~ (all equal) Record8_Parallel-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_8Tags-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) ```
howardjohn
added a commit
to howardjohn/opencensus-go
that referenced
this pull request
Sep 14, 2021
This is built upon census-instrumentation#1267; that one should likely merge first. I split this out as it has a small public API change (to work around circular imports) to avoid issues on the first PR. Benchmark relative to census-instrumentation#1267: ``` me old time/op new time/op delta Record0-6 1.74ns ± 4% 1.79ns ± 2% +2.85% (p=0.238 n=5+5) Record1-6 634ns ± 6% 542ns ± 9% -14.55% (p=0.008 n=5+5) Record8-6 1.21µs ± 5% 1.23µs ± 2% +1.97% (p=0.254 n=5+5) Record8_WithRecorder-6 777ns ± 5% 792ns ± 5% +1.97% (p=0.421 n=5+5) Record8_Parallel-6 1.26µs ±24% 1.22µs ± 2% ~ (p=0.690 n=5+5) Record8_8Tags-6 1.23µs ± 2% 1.25µs ± 3% ~ (p=0.651 n=5+5) name old alloc/op new alloc/op delta Record0-6 0.00B 0.00B ~ (all equal) Record1-6 120B ± 0% 96B ± 0% -20.00% (p=0.008 n=5+5) Record8-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_WithRecorder-6 424B ± 0% 424B ± 0% ~ (all equal) Record8_Parallel-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_8Tags-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Record0-6 0.00 0.00 ~ (all equal) Record1-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_WithRecorder-6 4.00 ± 0% 4.00 ± 0% ~ (all equal) Record8_Parallel-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_8Tags-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) ```
howardjohn
added a commit
to howardjohn/opencensus-go
that referenced
this pull request
Sep 14, 2021
This is built upon census-instrumentation#1267; that one should likely merge first. I split this out as it has a small public API change (to work around circular imports) to avoid issues on the first PR. Benchmark relative to census-instrumentation#1267: ``` me old time/op new time/op delta Record0-6 1.74ns ± 4% 1.79ns ± 2% +2.85% (p=0.238 n=5+5) Record1-6 634ns ± 6% 542ns ± 9% -14.55% (p=0.008 n=5+5) Record8-6 1.21µs ± 5% 1.23µs ± 2% +1.97% (p=0.254 n=5+5) Record8_WithRecorder-6 777ns ± 5% 792ns ± 5% +1.97% (p=0.421 n=5+5) Record8_Parallel-6 1.26µs ±24% 1.22µs ± 2% ~ (p=0.690 n=5+5) Record8_8Tags-6 1.23µs ± 2% 1.25µs ± 3% ~ (p=0.651 n=5+5) name old alloc/op new alloc/op delta Record0-6 0.00B 0.00B ~ (all equal) Record1-6 120B ± 0% 96B ± 0% -20.00% (p=0.008 n=5+5) Record8-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_WithRecorder-6 424B ± 0% 424B ± 0% ~ (all equal) Record8_Parallel-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_8Tags-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Record0-6 0.00 0.00 ~ (all equal) Record1-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_WithRecorder-6 4.00 ± 0% 4.00 ± 0% ~ (all equal) Record8_Parallel-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_8Tags-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) ```
howardjohn
added a commit
to howardjohn/opencensus-go
that referenced
this pull request
Sep 14, 2021
This is built upon census-instrumentation#1267; that one should likely merge first. I split this out as it has a small public API change (to work around circular imports) to avoid issues on the first PR. Benchmark relative to census-instrumentation#1267: ``` me old time/op new time/op delta Record0-6 1.74ns ± 4% 1.79ns ± 2% +2.85% (p=0.238 n=5+5) Record1-6 634ns ± 6% 542ns ± 9% -14.55% (p=0.008 n=5+5) Record8-6 1.21µs ± 5% 1.23µs ± 2% +1.97% (p=0.254 n=5+5) Record8_WithRecorder-6 777ns ± 5% 792ns ± 5% +1.97% (p=0.421 n=5+5) Record8_Parallel-6 1.26µs ±24% 1.22µs ± 2% ~ (p=0.690 n=5+5) Record8_8Tags-6 1.23µs ± 2% 1.25µs ± 3% ~ (p=0.651 n=5+5) name old alloc/op new alloc/op delta Record0-6 0.00B 0.00B ~ (all equal) Record1-6 120B ± 0% 96B ± 0% -20.00% (p=0.008 n=5+5) Record8-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_WithRecorder-6 424B ± 0% 424B ± 0% ~ (all equal) Record8_Parallel-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_8Tags-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Record0-6 0.00 0.00 ~ (all equal) Record1-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_WithRecorder-6 4.00 ± 0% 4.00 ± 0% ~ (all equal) Record8_Parallel-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_8Tags-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) ```
dashpole
pushed a commit
that referenced
this pull request
Oct 21, 2021
* Remove `convTslice` calls in `Record()` This is built upon #1267; that one should likely merge first. I split this out as it has a small public API change (to work around circular imports) to avoid issues on the first PR. Benchmark relative to #1267: ``` me old time/op new time/op delta Record0-6 1.74ns ± 4% 1.79ns ± 2% +2.85% (p=0.238 n=5+5) Record1-6 634ns ± 6% 542ns ± 9% -14.55% (p=0.008 n=5+5) Record8-6 1.21µs ± 5% 1.23µs ± 2% +1.97% (p=0.254 n=5+5) Record8_WithRecorder-6 777ns ± 5% 792ns ± 5% +1.97% (p=0.421 n=5+5) Record8_Parallel-6 1.26µs ±24% 1.22µs ± 2% ~ (p=0.690 n=5+5) Record8_8Tags-6 1.23µs ± 2% 1.25µs ± 3% ~ (p=0.651 n=5+5) name old alloc/op new alloc/op delta Record0-6 0.00B 0.00B ~ (all equal) Record1-6 120B ± 0% 96B ± 0% -20.00% (p=0.008 n=5+5) Record8-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_WithRecorder-6 424B ± 0% 424B ± 0% ~ (all equal) Record8_Parallel-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) Record8_8Tags-6 344B ± 0% 320B ± 0% -6.98% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Record0-6 0.00 0.00 ~ (all equal) Record1-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_WithRecorder-6 4.00 ± 0% 4.00 ± 0% ~ (all equal) Record8_Parallel-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) Record8_8Tags-6 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5) ``` * Refactor to avoid leaking into public API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently,
Record()re-uses code withRecordWithOptions. This always createsallocations for createRecordOption, which is not needed in this case - we only
have measurements and not generic options.
With a little code duplication, we can reduce these allocations.
Note to reviewers: This PR has two commits. The first is broken out into #1266; likely that should be merged first
For #1265