This repository was archived by the owner on Jul 31, 2023. It is now read-only.
Precompute encodeWithKeys buffer size to avoid resizes#1269
Merged
dashpole merged 1 commit intocensus-instrumentation:masterfrom Sep 14, 2021
Merged
Conversation
0009364 to
7689b28
Compare
Contributor
Author
|
I don't think the test failure is from my test. Maybe its a flaky test? Its in the tracing code, not stats. |
dashpole
reviewed
Sep 14, 2021
stats/view/collector.go
Outdated
| // encodeWithKeys encodes the map by using values | ||
| // only associated with the keys provided. | ||
| func encodeWithKeys(m *tag.Map, keys []tag.Key) []byte { | ||
| // Compute the buffer length we will need ahead of time to avoid resizing latter |
Collaborator
|
Well, fix the typo, and hopefully it doesn't flake this time :) |
This is strictly an optimization. Right now we always undersize the buffer then later increase it. This changes the code to accurately size it the first time to ensure we never re-allocate. ``` name old time/op new time/op delta RecordReqCommand-6 2.26µs ± 5% 2.10µs ± 5% -7.39% (p=0.000 n=10+10) RecordViaStats-6 2.70µs ± 5% 2.53µs ± 4% -6.31% (p=0.000 n=10+10) name old alloc/op new alloc/op delta RecordReqCommand-6 426B ± 0% 384B ± 0% -9.86% (p=0.000 n=10+10) RecordViaStats-6 594B ± 0% 552B ± 0% -7.07% (p=0.000 n=10+10) name old allocs/op new allocs/op delta RecordReqCommand-6 25.0 ± 0% 17.0 ± 0% -32.00% (p=0.000 n=10+10) RecordViaStats-6 28.0 ± 0% 20.0 ± 0% -28.57% (p=0.000 n=10+10) ```
7689b28 to
f8d6079
Compare
dashpole
approved these changes
Sep 14, 2021
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.
This is strictly an optimization. Right now we always undersize the buffer then later increase it.
This changes the code to accurately size it the first time to ensure we never re-allocate.
See #1265