-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Deprecate Array attribute in favor of *Slice types #2162
Merged
Merged
Conversation
This file contains 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
Codecov Report
@@ Coverage Diff @@
## main #2162 +/- ##
=======================================
+ Coverage 72.6% 72.8% +0.1%
=======================================
Files 177 177
Lines 12000 12140 +140
=======================================
+ Hits 8719 8840 +121
- Misses 3043 3063 +20
+ Partials 238 237 -1
|
MrAlias
force-pushed
the
array-attr
branch
2 times, most recently
from
August 6, 2021 00:01
3126a20
to
552c59c
Compare
I'm going to split off some of the cleanup tasks into other PRs to reduce the size here. |
This was referenced Aug 6, 2021
MrAlias
requested review from
Aneurysm9,
dashpole,
evantorrie,
jmacd,
MadVikingGod,
paivagustavo,
pellared and
XSAM
as code owners
August 11, 2021 19:21
Aneurysm9
approved these changes
Aug 11, 2021
jmacd
approved these changes
Aug 11, 2021
pellared
approved these changes
Aug 12, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #2158
Add
*Slice
attribute types as a replacement for the deprecatedArray
type.Benchmark Results
To compare the existing Array type with the new *Slice types the
*/Array/KeyValue
benchmark shows the "before" and the equivalent*Slice/Value
shows the "after" for the encoding. Similarly for the*/Array/Emit
and*Slice/Emit
.$ go test -bench=. goos: linux goarch: amd64 pkg: go.opentelemetry.io/otel/attribute cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz BenchmarkBool/Value-8 832225669 1.363 ns/op 0 B/op 0 allocs/op BenchmarkBool/KeyValue-8 141931221 8.458 ns/op 0 B/op 0 allocs/op BenchmarkBool/AsBool-8 833652847 1.439 ns/op 0 B/op 0 allocs/op BenchmarkBool/Any-8 58587181 20.87 ns/op 0 B/op 0 allocs/op BenchmarkBool/Emit-8 149373596 7.977 ns/op 0 B/op 0 allocs/op BenchmarkBool/Array/KeyValue-8 6737637 175.4 ns/op 6 B/op 2 allocs/op BenchmarkBool/Array/Emit-8 4434680 271.0 ns/op 24 B/op 1 allocs/op BenchmarkBoolSlice/Value-8 26688757 46.21 ns/op 27 B/op 2 allocs/op BenchmarkBoolSlice/KeyValue-8 22950921 49.40 ns/op 27 B/op 2 allocs/op BenchmarkBoolSlice/AsBoolSlice-8 525599371 2.272 ns/op 0 B/op 0 allocs/op BenchmarkBoolSlice/Any-8 16773865 71.35 ns/op 27 B/op 2 allocs/op BenchmarkBoolSlice/Emit-8 3257484 348.7 ns/op 27 B/op 4 allocs/op BenchmarkInt/Value-8 877902837 1.364 ns/op 0 B/op 0 allocs/op BenchmarkInt/KeyValue-8 142272414 8.431 ns/op 0 B/op 0 allocs/op BenchmarkInt/Any-8 60339177 19.81 ns/op 0 B/op 0 allocs/op BenchmarkInt/Emit-8 100000000 10.14 ns/op 0 B/op 0 allocs/op BenchmarkInt/Array/KeyValue-8 6178926 201.1 ns/op 48 B/op 2 allocs/op BenchmarkInt/Array/Emit-8 3916032 301.4 ns/op 16 B/op 1 allocs/op BenchmarkIntSlice/Value-8 21200500 55.04 ns/op 48 B/op 2 allocs/op BenchmarkIntSlice/KeyValue-8 17387926 65.81 ns/op 48 B/op 2 allocs/op BenchmarkIntSlice/Any-8 13910582 86.29 ns/op 48 B/op 2 allocs/op BenchmarkIntSlice/Emit-8 2681140 439.6 ns/op 40 B/op 4 allocs/op BenchmarkInt8/Any-8 61987556 20.22 ns/op 0 B/op 0 allocs/op BenchmarkInt16/Any-8 59654839 20.37 ns/op 0 B/op 0 allocs/op BenchmarkInt32/Any-8 57865954 20.38 ns/op 0 B/op 0 allocs/op BenchmarkInt64/Value-8 806119342 1.358 ns/op 0 B/op 0 allocs/op BenchmarkInt64/KeyValue-8 141895544 8.436 ns/op 0 B/op 0 allocs/op BenchmarkInt64/AsInt64-8 830603088 1.483 ns/op 0 B/op 0 allocs/op BenchmarkInt64/Any-8 57967998 21.18 ns/op 0 B/op 0 allocs/op BenchmarkInt64/Emit-8 100000000 10.36 ns/op 0 B/op 0 allocs/op BenchmarkInt64/Array/KeyValue-8 6219757 196.6 ns/op 48 B/op 2 allocs/op BenchmarkInt64/Array/Emit-8 3721778 323.0 ns/op 16 B/op 1 allocs/op BenchmarkInt64Slice/Value-8 23372196 51.28 ns/op 48 B/op 2 allocs/op BenchmarkInt64Slice/KeyValue-8 18154530 58.24 ns/op 48 B/op 2 allocs/op BenchmarkInt64Slice/AsInt64Slice-8 494594601 2.464 ns/op 0 B/op 0 allocs/op BenchmarkInt64Slice/Any-8 15182502 78.44 ns/op 48 B/op 2 allocs/op BenchmarkInt64Slice/Emit-8 2585980 461.1 ns/op 40 B/op 4 allocs/op BenchmarkFloat64/Value-8 875715577 1.437 ns/op 0 B/op 0 allocs/op BenchmarkFloat64/KeyValue-8 142405081 8.438 ns/op 0 B/op 0 allocs/op BenchmarkFloat64/AsFloat64-8 821869407 1.407 ns/op 0 B/op 0 allocs/op BenchmarkFloat64/Any-8 60712789 20.73 ns/op 0 B/op 0 allocs/op BenchmarkFloat64/Emit-8 8718868 137.9 ns/op 16 B/op 2 allocs/op BenchmarkFloat64/Array/KeyValue-8 5793618 200.9 ns/op 48 B/op 2 allocs/op BenchmarkFloat64/Array/Emit-8 2527147 472.9 ns/op 16 B/op 1 allocs/op BenchmarkFloat64Slice/Value-8 22137026 53.27 ns/op 48 B/op 2 allocs/op BenchmarkFloat64Slice/KeyValue-8 18504712 66.35 ns/op 48 B/op 2 allocs/op BenchmarkFloat64Slice/AsFloat64Slice-8 510276062 2.478 ns/op 0 B/op 0 allocs/op BenchmarkFloat64Slice/Any-8 15239098 89.51 ns/op 48 B/op 2 allocs/op BenchmarkFloat64Slice/Emit-8 1998475 596.2 ns/op 40 B/op 4 allocs/op BenchmarkString/Value-8 183353606 6.529 ns/op 0 B/op 0 allocs/op BenchmarkString/KeyValue-8 134076531 8.963 ns/op 0 B/op 0 allocs/op BenchmarkString/AsString-8 630018024 2.001 ns/op 0 B/op 0 allocs/op BenchmarkString/Any-8 53771318 23.64 ns/op 0 B/op 0 allocs/op BenchmarkString/Emit-8 168047347 7.531 ns/op 0 B/op 0 allocs/op BenchmarkString/Array/KeyValue-8 4995198 244.7 ns/op 96 B/op 2 allocs/op BenchmarkString/Array/Emit-8 3748335 319.4 ns/op 48 B/op 1 allocs/op BenchmarkStringSlice/Value-8 12286879 97.78 ns/op 72 B/op 2 allocs/op BenchmarkStringSlice/KeyValue-8 12281880 97.38 ns/op 72 B/op 2 allocs/op BenchmarkStringSlice/AsStringSlice-8 486037562 2.488 ns/op 0 B/op 0 allocs/op BenchmarkStringSlice/Any-8 9544404 126.2 ns/op 72 B/op 2 allocs/op BenchmarkStringSlice/Emit-8 2722761 447.6 ns/op 96 B/op 4 allocs/op BenchmarkBytes/Any-8 36801850 32.62 ns/op 0 B/op 0 allocs/op
The take-away:
[]bool
types takes a bit more memory,[]string
take a bit less, and number types are equivalent.Emit
users more memory and allocations. These extra allocations seem to be coming from thefmt.Sprint
function and the resizing of the underlying buffer it uses to build the string representation. I built a PoC for aBoolSlice
that optimized the buffer size prior to build a string directly and saw the allocations drop back to down. This seems like a place for future optimization if it is determined worth it.