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

Suggestion to change json parser in order to improve performance #76

Closed
ghost opened this issue Jun 15, 2017 · 6 comments
Closed

Suggestion to change json parser in order to improve performance #76

ghost opened this issue Jun 15, 2017 · 6 comments
Assignees
Labels

Comments

@ghost
Copy link

ghost commented Jun 15, 2017

Instead of using standard encoding/json, maybe use another like https://github.com/json-iterator/go

@jeevatkm jeevatkm self-assigned this Jun 16, 2017
@jeevatkm
Copy link
Member

Thank you for your suggestion. I will have a look.

@jeevatkm
Copy link
Member

jeevatkm commented Jul 10, 2017

@ZandorZ I have done my analysis.

json-iterator supports all three compliant methods

  • Marshal(v interface{}) ([]byte, error)
  • Unmarshal(data []byte, v interface{}) error
  • MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)

There are other two candid libraries are available:

ffjson supports two compliant methods

  • Marshal(v interface{}) ([]byte, error)
  • Unmarshal(data []byte, v interface{}) error

easyjson but this one is doesn't support drop-in replacement, so out-of-choice.

So, following is my design choice/approach:

  • By default use standard encoding/json package in resty
  • Expose option to register developer choice of JSON library into resty. Basically resty client will have two new fields
    • JSONMarshal func(v interface{}) ([]byte, error)
    • JSONUnmarshal func(data []byte, v interface{}) error

For example developer can register like this-

// For default client
resty.DefaultClient.JSONMarshal = jsoniter.Marshal
resty.DefaultClient.JSONUnmarshal = jsoniter.Unmarshal

// For custom client
myclient := resty.New()
myclient.JSONMarshal = jsoniter.Marshal
myclient.JSONUnmarshal = jsoniter.Unmarshal

I will give it try on the implementation and will post the outcome.

Do you have any suggestions?

@jeevatkm
Copy link
Member

I have implemented above mentioned design e621018, it is not yet merged to master.

@ghost
Copy link
Author

ghost commented Jul 10, 2017

@jeevatkm Good idea!

@jeevatkm
Copy link
Member

Merging e621018 into master.

@jeevatkm
Copy link
Member

Merged to master

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

No branches or pull requests

1 participant