Skip to content

Make json decoding faster #117

@kjk

Description

@kjk

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions