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

should encoder and decoder object be shared or created on demand? #534

Open
yangcheng opened this issue Sep 26, 2023 · 3 comments
Open

should encoder and decoder object be shared or created on demand? #534

yangcheng opened this issue Sep 26, 2023 · 3 comments

Comments

@yangcheng
Copy link

It's unclear from documentation what's the best practice to use encoder and decoder.

Should I keep a global encoder ? is the object thread-safe?

Thanks

@liuq19
Copy link
Collaborator

liuq19 commented Sep 26, 2023

Encoder or decoder is mostly used for streaming or some specific configurations, such as decoder with UseNumber, or encoder with SortKeys. And there are no benefits to reusing an encoder or decoder. So recommended not to use a shared encoder or decoder.

@yangcheng
Copy link
Author

yangcheng commented Sep 26, 2023

good to know that, I was about to use encoder for streaming io as mentioned in https://github.com/bytedance/sonic#streaming-io , no specific configuration, just http write response. is it recommended to simplely use Marshal ?

The reason I am asking is I noticed very similar performance os sonic encoder vs json encoder in my test and I am curious if I did something wrong

@liuq19
Copy link
Collaborator

liuq19 commented Sep 26, 2023

good to know that, I was about to use encoder for streaming io as mentioned in https://github.com/bytedance/sonic#streaming-io , no specific configuration, just http write response. is it recommended to simplely use Marshal ?

yes, if not in streaming scenes or specific configuration, just use Marshal

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

2 participants