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

how does it compare to the "canonical" option of sone #1

Open
benoitc opened this issue Oct 8, 2017 · 1 comment
Open

how does it compare to the "canonical" option of sone #1

benoitc opened this issue Oct 8, 2017 · 1 comment

Comments

@benoitc
Copy link

benoitc commented Oct 8, 2017

Hi I wondered if you compared the performance of your lib against using the "canonical" option I added to jsone? Which provide a canonical form of son that can be use for hashing.

Also can you describe the way you're creating a sorted JSON? what are the properties you're taking care ?

@potatosalad
Copy link
Owner

@benoitc jsone with canonical_form is roughly 4-5x faster than ojson currently:

benchmark name               iterations   average time 
maps (jsone)                    1000000   23.99 µs/op
maps (jsone canonical_form)      500000   32.79 µs/op
maps (OJSON iodata)              100000   127.97 µs/op
maps (OJSON)                     100000   140.12 µs/op

Also can you describe the way you're creating a sorted JSON?

Using lists:sort/1 in ojson_encoder, similar to what jsone_encode does.

The main goal of this project was to have stable/ordered/predictable output by default for use in cryptography operations and for it to be useful as a drop-in replacement to devinus/poison for Elixir as well as for Erlang projects.

I wasn't aware of the canonical_form option and I don't think it was yet implemented back when I added jsone as a JSON adapter to jose.

However, jsone definitely has a faster implementation. I looked into a few of the JSON libraries already out there before writing ojson, but there are a few behavioural differences in jsone that I wish weren't present on the implementation side of things, like ignoring garbage data after a valid JSON term:

jsone:decode(<<"[1,2,3] garbage">>).
% [1, 2, 3]

Compared to ojson:

ojson:decode(<<"[1,2,3] garbage">>).
% {error, {invalid, <<"g">>, 8}}

For Elixir users, there are also a few things missing from jsone currently that would make it more "friendly" or compatible with Poison as a drop-in replacement. Streaming support is also absent from both libraries, but present in jsx. I'm rambling a little now, but hopefully that explains what my intent was for ojson.

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