-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
encoding/protojson: poor serialization performance #1285
Comments
The |
The main reason that https://developers.google.com/protocol-buffers/docs/proto3#json |
I want to use encoding/json. Can I implement MarshalJSON and UnmarshalJSON interfaces for known types?
|
That's not true. There are many reasons why
Let's keep this topic about improving performance. Trying to serialize int64 as a JSON number is an unrelated concern. |
Another potential performance optimization is to allow to disable field sorting. Any/random order is fine in most situations. |
Are there any current plans for this optimization? |
Hi, afaik the issue tracker continues to be this one both for this and the newer protobuf-go repo, let me know if that's not the case. I've submitted a PR to improve marshaling performance at https://go-review.googlesource.com/c/protobuf/+/373356
Boring details: I've added the 'Unordered' marshalopt on the |
With |
updated |
going back to this in a bit, on vacation rn |
This change speeds up the stdin segment by moving the unmarshalling step of protojson into a goroutine. The protojson implementation is known to be not as optimized as the stdlib json implementation [1]. This change improves performance with more parallelization, leading to the following speedups on an AMD EPYC 7742 dual-socket server: nr. of records in JSON | old wall time | new wall time | speedup 5473180 | 1m53.214s | 0m55.954s | 50% 16002618 | 5m35.092s | 2m48.978s | 50% This might lead to the reordering of records, which might also happen on other input segments like goflow. Instead, users should depend on sequence numbers and timestamps in the EnhancedFlow struct. [1] golang/protobuf#1285
This change speeds up the stdin segment by moving the unmarshalling step of protojson into a goroutine. The protojson implementation is known to be not as optimized as the stdlib json implementation [1]. This change improves performance with more parallelization, leading to the following speedups on an AMD EPYC 7742 dual-socket server: | nr. of records in JSON | old wall time | new wall time | speedup | | ---------------------- | ------------- | ------------- | ------- | | 5473180 | 1m53.214s | 0m55.954s | 50% | | 16002618 | 5m35.092s | 2m48.978s | 50% | This might lead to the reordering of records, which might also happen on other input segments like goflow. Instead, users should depend on sequence numbers and timestamps in the EnhancedFlow struct. [1] golang/protobuf#1285
https://github.com/tonybase/benchmark/tree/main/benchmark-protobuf-json:
It doesn't seem to optimize performance very well, and Encoder doesn't use a similar standard library EncodeStatePool to reduce object allocation
The text was updated successfully, but these errors were encountered: