-
Notifications
You must be signed in to change notification settings - Fork 16
Description
This is a nice to have.
Currently json -> result (usually a struct) happens in 2 stages:
- first we decode json to
map[string]interface{}and we cache that in session - to return a result to a user, we decode
map[string]interfac{}to a struct
The second conversion (makeStructFromJSONMap) is inefficicent. We convert map[string]interface{} to json string and then decode that string to a struct. The reason I did it this way: it was trivial to implement (re-using standard library json.Marshal and json.Unmarshal).
One way to speed it up is to rewrite makeStructFromJSONMap to be more efficient. I started that work for unrelated issue but it wasn't necessary to fix that issue so I benched it. The code is in a branch https://github.com/ravendb/ravendb-go-client/tree/faster-map-to-struct.
The code is basically "porting" the code from json.Unmarshal to use map[string]interface{} as input instead of json string. Probably can be done in 2-3 days.
Other ideas to improve performance:
- benchmark and test third-party json decoding libraries that claim to be faster than
encoding\jsonfrom standard library (like https://github.com/json-iterator/go or https://github.com/francoispqt/gojay). - consider caching documents in more performant way than map[string]interface{}