internal/protocol/json: Reduce unmarshal allocs#376
Conversation
Check PkgPath on StructField which will be empty for exported fields (http://golang.org/pkg/reflect/#StructField).
|
This is the same technique that the json standard library uses (https://github.com/golang/go/blob/932c1e3dd32f636ab3f25b23d9dcef194a577bca/src/encoding/json/encode.go#L1025) to check if a field is export so it should be correct. |
|
Great find @bpot ! Thanks for submitting this PR. Allocations of the protocol marshallers is something we definitely want to improve. There are a series of benchmarks in I noticed this issue is present in several of the other marshallers, so similar fixes might be able to be applied to them also. I created #377 to track improving the protocol marshallers in general. |
internal/protocol/json: Reduce unmarshal allocs
|
Thanks! |
Check PkgPath on StructField which will be empty for exported fields
(http://golang.org/pkg/reflect/#StructField).
We have an application which heavily uses DynamoDB and we are seeing a lot of allocations in
jsonutil/unmarshal. Based on a heap dump nearly 25% of the allocations (program wide) are coming fromstrings.ToLowerin unmarshalStruct: