-
Notifications
You must be signed in to change notification settings - Fork 234
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
performance issue #256
Comments
I haven't used ffjson in a long time so I might be wrong, but this is the only way I could get your code fast: func BenchmarkFFJson(b *testing.B) {
d := Demo{
A: 1,
B: "asd",
}
buf := &fflib.Buffer{}
for i := 0; i < b.N; i++ {
if err := d.MarshalJSONBuf(buf); err != nil {
panic(err)
}
_ = buf.Bytes()
buf.Reset()
}
} I also had to apply this patch to get ffjson down to 0 allocations: https://gist.github.com/erikdubbelboer/898d219bbc997ab1e9aeee2d64aafa04 The result:
|
Hi @erikdubbelboer, After dig into this more, I compare ffjson/easyjson/jsoniter, it's surprising ffjson is the slowest, with highest allocs.
repo for this benchmark: |
Correct but this is to convert a string to a I always use easyjson, that's why I said I haven't used ffjson in a long time. |
if convert |
That will only work in cases where you never look at the capacity of the returned slice. If you do something that looks at the capacity it will fail horribly as it will use the memory after the string header as capacity and you have on idea what is stored there. |
I got your point, thanks for your explanation. |
go test -run ^NOTHING -bench Jsoncost$ -v
Then, I use ffjson to generate custom MarshalJSON for Demo struct, update
json.Marshal(d)
toffjson.Marshal(d)
, run benchmark againIt seems ffjson is slower than encoding/json, is there anything I'm missing ?
The text was updated successfully, but these errors were encountered: