mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-05-15 22:06:40 +02:00
remove Set.Encoded(Encoder) enconding cache (#1855)
* remove Set.Encoded(Encoder) enconding cache Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
parent
7674eebf56
commit
2bd4840c30
@ -29,6 +29,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
- `resource.New()` now creates a Resource without builtin detectors. Previous behavior is now achieved by using `WithBuiltinDetectors` Option. (#1810)
|
- `resource.New()` now creates a Resource without builtin detectors. Previous behavior is now achieved by using `WithBuiltinDetectors` Option. (#1810)
|
||||||
- Move the `Event` type from the `go.opentelemetry.io/otel` package to the `go.opentelemetry.io/otel/sdk/trace` package. (#1846)
|
- Move the `Event` type from the `go.opentelemetry.io/otel` package to the `go.opentelemetry.io/otel/sdk/trace` package. (#1846)
|
||||||
- BatchSpanProcessor now report export failures when calling `ForceFlush()` method. (#1860)
|
- BatchSpanProcessor now report export failures when calling `ForceFlush()` method. (#1860)
|
||||||
|
- `Set.Encoded(Encoder)` no longer caches the result of an encoding. (#1855)
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -35,10 +34,6 @@ type (
|
|||||||
// 3. Correlation map (TODO)
|
// 3. Correlation map (TODO)
|
||||||
Set struct {
|
Set struct {
|
||||||
equivalent Distinct
|
equivalent Distinct
|
||||||
|
|
||||||
lock sync.Mutex
|
|
||||||
encoders [maxConcurrentEncoders]EncoderID
|
|
||||||
encoded [maxConcurrentEncoders]string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Distinct wraps a variable-size array of `KeyValue`,
|
// Distinct wraps a variable-size array of `KeyValue`,
|
||||||
@ -76,8 +71,6 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxConcurrentEncoders = 3
|
|
||||||
|
|
||||||
// EmptySet returns a reference to a Set with no elements.
|
// EmptySet returns a reference to a Set with no elements.
|
||||||
//
|
//
|
||||||
// This is a convenience provided for optimized calling utility.
|
// This is a convenience provided for optimized calling utility.
|
||||||
@ -182,53 +175,15 @@ func (l *Set) Equals(o *Set) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Encoded returns the encoded form of this set, according to
|
// Encoded returns the encoded form of this set, according to
|
||||||
// `encoder`. The result will be cached in this `*Set`.
|
// `encoder`.
|
||||||
func (l *Set) Encoded(encoder Encoder) string {
|
func (l *Set) Encoded(encoder Encoder) string {
|
||||||
if l == nil || encoder == nil {
|
if l == nil || encoder == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
id := encoder.ID()
|
|
||||||
if !id.Valid() {
|
|
||||||
// Invalid IDs are not cached.
|
|
||||||
return encoder.Encode(l.Iter())
|
return encoder.Encode(l.Iter())
|
||||||
}
|
}
|
||||||
|
|
||||||
var lookup *string
|
|
||||||
l.lock.Lock()
|
|
||||||
for idx := 0; idx < maxConcurrentEncoders; idx++ {
|
|
||||||
if l.encoders[idx] == id {
|
|
||||||
lookup = &l.encoded[idx]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
l.lock.Unlock()
|
|
||||||
|
|
||||||
if lookup != nil {
|
|
||||||
return *lookup
|
|
||||||
}
|
|
||||||
|
|
||||||
r := encoder.Encode(l.Iter())
|
|
||||||
|
|
||||||
l.lock.Lock()
|
|
||||||
defer l.lock.Unlock()
|
|
||||||
|
|
||||||
for idx := 0; idx < maxConcurrentEncoders; idx++ {
|
|
||||||
if l.encoders[idx] == id {
|
|
||||||
return l.encoded[idx]
|
|
||||||
}
|
|
||||||
if !l.encoders[idx].Valid() {
|
|
||||||
l.encoders[idx] = id
|
|
||||||
l.encoded[idx] = r
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: This is a performance cliff. Find a way for this to
|
|
||||||
// generate a warning.
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func empty() Set {
|
func empty() Set {
|
||||||
return Set{
|
return Set{
|
||||||
equivalent: emptySet.equivalent,
|
equivalent: emptySet.equivalent,
|
||||||
@ -246,7 +201,7 @@ func NewSet(kvs ...KeyValue) Set {
|
|||||||
return empty()
|
return empty()
|
||||||
}
|
}
|
||||||
s, _ := NewSetWithSortableFiltered(kvs, new(Sortable), nil)
|
s, _ := NewSetWithSortableFiltered(kvs, new(Sortable), nil)
|
||||||
return s //nolint
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSetWithSortable returns a new `Set`. See the documentation for
|
// NewSetWithSortable returns a new `Set`. See the documentation for
|
||||||
@ -259,7 +214,7 @@ func NewSetWithSortable(kvs []KeyValue, tmp *Sortable) Set {
|
|||||||
return empty()
|
return empty()
|
||||||
}
|
}
|
||||||
s, _ := NewSetWithSortableFiltered(kvs, tmp, nil)
|
s, _ := NewSetWithSortableFiltered(kvs, tmp, nil)
|
||||||
return s //nolint
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSetWithFiltered returns a new `Set`. See the documentation for
|
// NewSetWithFiltered returns a new `Set`. See the documentation for
|
||||||
|
Loading…
x
Reference in New Issue
Block a user