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

Consider using code generation (ex: easyjson) for JSON models #76

Open
3 tasks done
bored-engineer opened this issue Apr 18, 2020 · 0 comments
Open
3 tasks done

Comments

@bored-engineer
Copy link
Contributor

bored-engineer commented Apr 18, 2020

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Description

Currently go-audit uses the stdlib encoding/json class to marshal the AuditMessageGroup and AuditMessage structs into a []byte. Internally the encoding/json package uses reflection so it can marshal arbitrary objects.

Because go-audit only uses two static structures there would likely be a significant performance improvement using a code generation library like easyjson to serialize the structures into bytes.

You can find various benchmarks on JSON serialization performance across code generation packages vs stdlib but I am partial to go_serialization_benchmarks:

benchmark iter time/iter bytes/op allocs/op tt.sec tt.kb ns/alloc
BenchmarkJsonMarshal-8 1000000 1585 ns/op 304 4 1.58 30400 396.25
BenchmarkEasyJsonMarshal-8 1000000 1125 ns/op 784 5 1.12 78400 225.00

This comes at the cost of an additional dependency (primarily when the models change only)

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

1 participant