Skip to content
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

gogo jsonpb is 10x slower than golang json Unmarshal? #699

Open
blackbeans opened this issue Jul 6, 2020 · 0 comments
Open

gogo jsonpb is 10x slower than golang json Unmarshal? #699

blackbeans opened this issue Jul 6, 2020 · 0 comments

Comments

@blackbeans
Copy link

Go version:1.13
protobuf: 3.6.x

code :


message Cursor {
    string ID = 1 [json_name = "id",(gogoproto.jsontag)="id"]; 
    uint32 Type = 2 [json_name = "type",(gogoproto.jsontag)="type",(gogoproto.customtype)="uint16",(gogoproto.nullable) = false]; 
    int64 Offset = 3 [json_name = "offset",(gogoproto.jsontag)="offset",(gogoproto.nullable) = false,(gogoproto.customtype) ="encoding/json.Number"]; 
    int64 QTimestamp = 4 [json_name = "timestamp",(gogoproto.jsontag)="timestamp",(gogoproto.nullable) = false,(gogoproto.customtype) ="encoding/json.Number"];
    int64 EndOffset = 5 [json_name = "end_offset",(gogoproto.jsontag)="end_offset",(gogoproto.nullable) = false,(gogoproto.customtype) ="encoding/json.Number"]; 
}


func BenchmarkJsonPb(t *testing.B) {
	rawMark := []byte(`{"id":"1224","type":2,"offset":9136,"timestamp":1593935873,"end_offset":0}`)
	unmarshaler := &jsonpb.Unmarshaler{AllowUnknownFields: true}
	for i := 0; i < t.N; i++ {
		var cursor Cursor
		unmarshaler.Unmarshal(bytes.NewReader(rawMark), &cursor)
	}
}

func BenchmarkJson(t *testing.B) {
	rawMark := []byte(`{"id":"1224","type":2,"offset":9136,"timestamp":1593935873,"end_offset":0}`)

	for i := 0; i < t.N; i++ {
		var cursor Cursor
		json.Unmarshal(rawMark, &cursor)
	}
}
goos: darwin
goarch: amd64
BenchmarkJsonPb-4         104812             11316 ns/op
BenchmarkJson-4           671342              1805 ns/op


above all, i have upgrade our project to protobuf and used jsonpb to output json format for communication .But i found than jsonpb Unmarshals the same json-data is 10x slower than golang 1.13.x .

i lost my way~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant