This feature is protected by a featuregate that is not yet enabled and
only marked as alpha. Preliminary results show > 20% CPU performance
improvement and at least 40% allocations improvement. I still need to
generate UnmarshalProto for AnyValue which should improve even more
results.
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Also, this PR improves JSON unmarshal logic by avoiding stack calls
caused by using the Read[Array|Object]CB and replace with simple
non-recursive iterations.
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
The only non-test change is in the Unmarshal proto but that generates
exactly the same code using the "defaultValue" for the message.
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Add support to generate the proto Size by pdatagen. Not yet used, will
update after more tests are added.
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Remove the complication about internal/public for all funcs that only
need origin. Also improves significant testing.
This simplified a lot the fields (no more isCommon/isBaseCommon/etc.)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This PR allows to add tests for CopyOrig directly in the internal
package, also enables us to move more things to internal (including
tests) for Marshal/Unmarshal.
After this PR is merged we can generate the ProtoSize and other proto
helpers in internal.
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Main idea is to have all funcs that work on "origin" in internal, so
that we simplify access to them (see field access to this). Also will
remove duplicate generated code like copying the slice of KeyValue
(followup PR).
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Part of the effort in
https://github.com/open-telemetry/opentelemetry-collector/pull/13531.
Would also help with:
1. Help with trying to remove the need of manually define these extra
structs and generate them from the protoc parsed code.
1. Simplifies what we need to manually generate, only the proto type is
enough.
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This PR is part of an effort to remove usage of gogo proto in pdata and
switch to a model where we enhance the pdatagen tool to generate compact
(reflection free to avoid DCE disabling) and faster code.
The list of the PRs will do:
1. Auto generate the JSON marshaling logic (this PR).
1. Auto generate the JSON unmarshaling logic and replace manually
written code.
1. Auto generate the proto marshaling logic.
1. Auto generate the proto unmarshaling logic.
1. Remove the usage of auto-generate gogo proto code completely and
generate field members in the pdata objects.
1. Add support for lazy unmarshaling.
Performance improvements are more than 30x:
**Before:**
```
BenchmarkLogsMarshalJSON
BenchmarkLogsMarshalJSON-12 94 12541041 ns/op 8458944 B/op 196458 allocs/op
BenchmarkMetricsMarshalJSON
BenchmarkMetricsMarshalJSON-12 3 452309069 ns/op 350229024 B/op 8131400 allocs/op
BenchmarkProfilesMarshalJSON
BenchmarkProfilesMarshalJSON-12 30 36731071 ns/op 20317088 B/op 531652 allocs/op
BenchmarkTracesMarshalJSON
BenchmarkTracesMarshalJSON-12 8 132521260 ns/op 95920588 B/op 2208765 allocs/op
```
**After:**
```
BenchmarkLogsMarshalJSON
BenchmarkLogsMarshalJSON-12 3000 403587 ns/op 282465 B/op 1487 allocs/op
BenchmarkMetricsMarshalJSON
BenchmarkMetricsMarshalJSON-12 72 16772373 ns/op 11856529 B/op 72833 allocs/op
BenchmarkProfilesMarshalJSON
BenchmarkProfilesMarshalJSON-12 1460 849419 ns/op 674545 B/op 1145 allocs/op
BenchmarkTracesMarshalJSON
BenchmarkTracesMarshalJSON-12 271 4344647 ns/op 3010259 B/op 16237 allocs/op
```
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>