Skip to content

encoding/protojson: poor serialization performance #1285

Open
@tonybase

Description

@tonybase

https://github.com/tonybase/benchmark/tree/main/benchmark-protobuf-json:

➜  benchmark-protobuf-json git:(main) go test -bench=. -benchmem
goos: darwin
goarch: amd64
pkg: github.com/tonybase/benchmark/benchmark-protobuf-json
cpu: Intel(R) Core(TM) i7-8557U CPU @ 1.70GHz
BenchmarkOrderProto3Marshal-8     	 3230240	       352.5 ns/op	     112 B/op	       1 allocs/op
BenchmarkOrderJSONMarshal-8       	 1411366	       858.9 ns/op	     240 B/op	       1 allocs/op
BenchmarkOrderJSONPBMarshal-8     	  259860	      4432 ns/op	    1016 B/op	      29 allocs/op
BenchmarkOrderProto3Unmarshal-8   	 1879772	       630.8 ns/op	     368 B/op	      11 allocs/op
BenchmarkOrderJSONUnmarshal-8     	  288832	      3992 ns/op	     696 B/op	      20 allocs/op
BenchmarkOrderJSONPBUnmarshal-8   	  181722	      6217 ns/op	    1088 B/op	      56 allocs/op
PASS
ok  	github.com/tonybase/benchmark/benchmark-protobuf-json	9.430s

It doesn't seem to optimize performance very well, and Encoder doesn't use a similar standard library EncodeStatePool to reduce object allocation

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions