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

Improve json encoding performance for specs-go #343

Merged
merged 3 commits into from
Mar 17, 2016

Conversation

crosbymichael
Copy link
Member

By using ffjson for json encoding we can reduce the time for encoding
and decoding.

Without:

BenchmarkMarsalSpec-4 100000 18276 ns/op
BenchmarkUnmarshal-4 30000 55115 ns/op

With:

BenchmarkMarsalSpec-4 100000 13649 ns/op
BenchmarkUnmarshal-4 50000 24747 ns/op

This is a reduces time about 25% on marshal and 50% on unmarshal.

I think its worth it to use ffjson as there is really no changes other than needing to generate the code after a change and we get good benefits in return.

This adds basic benchmark tests for the performace of marshaling and
unmarshaling the spec into json.  These tests are helpful to optimize
the performace because the main way the spec is consumed is via json.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
By using ffjson for json encoding we can reduce the time for encoding
and decoding.

Without:

BenchmarkMarsalSpec-4     100000             18276 ns/op
BenchmarkUnmarshal-4       30000             55115 ns/op

With:

BenchmarkMarsalSpec-4     100000             13649 ns/op
BenchmarkUnmarshal-4       50000             24747 ns/op

This is a reduces time about 25% on marshal and 50% on unmarshal.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
@vbatts
Copy link
Member

vbatts commented Mar 16, 2016

not that i'm disagreeing with it, but I we don't much do any marshaling in the source of this repo presently. Though perhaps it makes sense to be present in the same package?

@crosbymichael
Copy link
Member Author

@vbatts ya, its for consumers of the package that we provide this. It really helps out alot. i.e. these functions have to be in the same package

@jessfraz
Copy link

imma use it 😇 i just updated all my tools

@vbatts
Copy link
Member

vbatts commented Mar 16, 2016

Then ought we put a target in the Makefile or go generate in the other source?

@crosbymichael
Copy link
Member Author

@vbatts updated makefile

},
}

func BenchmarkMarsalSpec(b *testing.B) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo s/Marsal/Marshal/

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
@mrunalp
Copy link
Contributor

mrunalp commented Mar 16, 2016

LGTM

@@ -56,6 +56,11 @@ test: .govet .golint .gitvalidation
.gitvalidation:
git-validation -q -run DCO,short-subject -v -range $(EPOCH_TEST_COMMIT)..HEAD

# `go get https://github.com/pquerna/ffjson`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s!https://!!

@vbatts
Copy link
Member

vbatts commented Mar 17, 2016

LGTM beside silly nit

vbatts added a commit that referenced this pull request Mar 17, 2016
Improve json encoding performance for specs-go
@vbatts vbatts merged commit a306c58 into opencontainers:master Mar 17, 2016
@crosbymichael crosbymichael deleted the marshal-performance branch March 17, 2016 19:03
@marcosnils
Copy link

@crosbymichael @vbatts time to move to easyjson?. https://github.com/mailru/easyjson

wking added a commit to wking/opencontainer-runtime-spec that referenced this pull request Apr 12, 2016
Through 6734c7a (Merge pull request opencontainers#370 from
vbatts/json_schema_and_examples, 2016-04-11).

The only unlisted changes to master were a brief run with ffjson
(opencontainers#343, opencontainers#351), but that was pulled out due to gccgo issues in opencontainers#363.

Signed-off-by: W. Trevor King <wking@tremily.us>
wking added a commit to wking/opencontainer-runtime-spec that referenced this pull request Apr 12, 2016
Through 6734c7a (Merge pull request opencontainers#370 from
vbatts/json_schema_and_examples, 2016-04-11).

The only unlisted changes to master were a brief run with ffjson
(opencontainers#343, opencontainers#351), but that was pulled out due to gccgo issues in opencontainers#363.

Signed-off-by: W. Trevor King <wking@tremily.us>
vbatts pushed a commit to vbatts/oci-runtime-spec that referenced this pull request Apr 12, 2016
Through 6734c7a (Merge pull request opencontainers#370 from
vbatts/json_schema_and_examples, 2016-04-11).

The only unlisted changes to master were a brief run with ffjson
(opencontainers#343, opencontainers#351), but that was pulled out due to gccgo issues in opencontainers#363.

Signed-off-by: W. Trevor King <wking@tremily.us>
Mashimiao pushed a commit to Mashimiao/specs that referenced this pull request Aug 19, 2016
Through 6734c7a (Merge pull request opencontainers#370 from
vbatts/json_schema_and_examples, 2016-04-11).

The only unlisted changes to master were a brief run with ffjson
(opencontainers#343, opencontainers#351), but that was pulled out due to gccgo issues in opencontainers#363.

Signed-off-by: W. Trevor King <wking@tremily.us>
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

Successfully merging this pull request may close these issues.

6 participants