Skip to content

Commit

Permalink
test(otel): slightly optimize OTEL/Write
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Feb 11, 2022
1 parent c8ebbd1 commit 19abaea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ e.g. using `[16]byte` for `TraceId` with zero-allocation `hex` encoding in json:
| Decode | 970 MB/s | 0 allocs/op |
| Validate | 1535 MB/s | 0 allocs/op |
| Encode | 1104 MB/s | 0 allocs/op |
| Write | 1800 MB/s | 0 allocs/op |
| Write | 2146 MB/s | 0 allocs/op |

See [otel_test.go](./otel_test.go) for example.

Expand Down
13 changes: 6 additions & 7 deletions otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ func (m *Map) Append(k, v []byte) {

func (m Map) Write(w *Writer) {
w.ObjStart()
defer w.ObjEnd()
_ = m.Keys.ForEachBytes(func(i int, b []byte) error {
if i > 0 {
for i, p := range m.Keys.Pos {
if i != 0 {
w.Comma()
}
w.FieldStart(string(b))
w.FieldStart(string(m.Keys.Buf[p.Start:p.End]))
w.Raw(m.Values.Elem(i))
return nil
})
}
w.ObjEnd()
}

func (m Map) Encode(e *Encoder) {
Expand Down Expand Up @@ -109,7 +108,6 @@ type OTEL struct {

func (o *OTEL) Write(w *Writer) {
w.ObjStart()
defer w.ObjEnd()

w.RawStr(`"Timestamp":`)
w.Num(o.Timestamp)
Expand Down Expand Up @@ -156,6 +154,7 @@ func (o *OTEL) Write(w *Writer) {

w.RawStr(`,"Body":`)
w.Raw(o.Body)
w.ObjEnd()
}

func (o *OTEL) Encode(e *Encoder) {
Expand Down

0 comments on commit 19abaea

Please sign in to comment.