and, in general, function calls like the plague, since they are quite
expensive in Go (compared to C). We have implemented basically the same for
our internal web framework (to be released some day) and we're almost 4x
faster than encoding/json without doing too much optimization. I'm sure we
could make this even faster.
// This is a small benchmark comparing the performance of these JSON
encoding
// methods. JSONDirect uses WriteJSON(), JSONSerialize uses
// gnd.la/mux/serialize (which adds some overhead because it also sets the
// Content-Length and Content-Encoding headers and thus must encode into an
// intermediate buffer first), while JSON uses json.Marshal(). All three
// benchmarks write the result to ioutil.Discard.
//
// BenchmarkJSONDirect 1000000 1248 ns/op 117.73 MB/s
// BenchmarkJSONSerialize 1000000 1587 ns/op 92.62 MB/s
// BenchmarkJSON 500000 4583 ns/op 32.07 MB/s
On Saturday, November 9, 2013 1:27:30 AM UTC+1, Ben Johnson wrote:
Hi everyone-
I've hit performance bottlenecks with JSON encoding on two projects (sky &
goraft) so I wrote an alternative called megajson. I noticed that a lot of
CPU time went to the "reflect" package to determine the appropriate types
to serialize so megajson takes the approach of generating parsers using the
"go/ast" package at compile time.
It's still in an alpha stage but I thought I'd post it to get some
feedback from people around my approach.
https://github.com/benbjohnson/megajson
Using the test data in encoding/json, megajson encodes and decodes about
2x faster. Obviously, YMMV.
Special thanks to Shopify for sponsoring the work on it.
Ben Johnson
--Hi everyone-
I've hit performance bottlenecks with JSON encoding on two projects (sky &
goraft) so I wrote an alternative called megajson. I noticed that a lot of
CPU time went to the "reflect" package to determine the appropriate types
to serialize so megajson takes the approach of generating parsers using the
"go/ast" package at compile time.
It's still in an alpha stage but I thought I'd post it to get some
feedback from people around my approach.
https://github.com/benbjohnson/megajson
Using the test data in encoding/json, megajson encodes and decodes about
2x faster. Obviously, YMMV.
Special thanks to Shopify for sponsoring the work on it.
Ben Johnson
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.