Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2bd4840

Browse files
remove Set.Encoded(Encoder) enconding cache (#1855)
* remove Set.Encoded(Encoder) enconding cache Co-authored-by: Tyler Yahn <[email protected]>
1 parent 7674eeb commit 2bd4840

2 files changed

Lines changed: 5 additions & 49 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2929
- `resource.New()` now creates a Resource without builtin detectors. Previous behavior is now achieved by using `WithBuiltinDetectors` Option. (#1810)
3030
- Move the `Event` type from the `go.opentelemetry.io/otel` package to the `go.opentelemetry.io/otel/sdk/trace` package. (#1846)
3131
- BatchSpanProcessor now report export failures when calling `ForceFlush()` method. (#1860)
32+
- `Set.Encoded(Encoder)` no longer caches the result of an encoding. (#1855)
3233

3334
### Deprecated
3435

attribute/set.go

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"encoding/json"
1919
"reflect"
2020
"sort"
21-
"sync"
2221
)
2322

2423
type (
@@ -35,10 +34,6 @@ type (
3534
// 3. Correlation map (TODO)
3635
Set struct {
3736
equivalent Distinct
38-
39-
lock sync.Mutex
40-
encoders [maxConcurrentEncoders]EncoderID
41-
encoded [maxConcurrentEncoders]string
4237
}
4338

4439
// Distinct wraps a variable-size array of `KeyValue`,
@@ -76,8 +71,6 @@ var (
7671
}
7772
)
7873

79-
const maxConcurrentEncoders = 3
80-
8174
// EmptySet returns a reference to a Set with no elements.
8275
//
8376
// This is a convenience provided for optimized calling utility.
@@ -182,51 +175,13 @@ func (l *Set) Equals(o *Set) bool {
182175
}
183176

184177
// Encoded returns the encoded form of this set, according to
185-
// `encoder`. The result will be cached in this `*Set`.
178+
// `encoder`.
186179
func (l *Set) Encoded(encoder Encoder) string {
187180
if l == nil || encoder == nil {
188181
return ""
189182
}
190183

191-
id := encoder.ID()
192-
if !id.Valid() {
193-
// Invalid IDs are not cached.
194-
return encoder.Encode(l.Iter())
195-
}
196-
197-
var lookup *string
198-
l.lock.Lock()
199-
for idx := 0; idx < maxConcurrentEncoders; idx++ {
200-
if l.encoders[idx] == id {
201-
lookup = &l.encoded[idx]
202-
break
203-
}
204-
}
205-
l.lock.Unlock()
206-
207-
if lookup != nil {
208-
return *lookup
209-
}
210-
211-
r := encoder.Encode(l.Iter())
212-
213-
l.lock.Lock()
214-
defer l.lock.Unlock()
215-
216-
for idx := 0; idx < maxConcurrentEncoders; idx++ {
217-
if l.encoders[idx] == id {
218-
return l.encoded[idx]
219-
}
220-
if !l.encoders[idx].Valid() {
221-
l.encoders[idx] = id
222-
l.encoded[idx] = r
223-
return r
224-
}
225-
}
226-
227-
// TODO: This is a performance cliff. Find a way for this to
228-
// generate a warning.
229-
return r
184+
return encoder.Encode(l.Iter())
230185
}
231186

232187
func empty() Set {
@@ -246,7 +201,7 @@ func NewSet(kvs ...KeyValue) Set {
246201
return empty()
247202
}
248203
s, _ := NewSetWithSortableFiltered(kvs, new(Sortable), nil)
249-
return s //nolint
204+
return s
250205
}
251206

252207
// NewSetWithSortable returns a new `Set`. See the documentation for
@@ -259,7 +214,7 @@ func NewSetWithSortable(kvs []KeyValue, tmp *Sortable) Set {
259214
return empty()
260215
}
261216
s, _ := NewSetWithSortableFiltered(kvs, tmp, nil)
262-
return s //nolint
217+
return s
263218
}
264219

265220
// NewSetWithFiltered returns a new `Set`. See the documentation for

0 commit comments

Comments
 (0)