-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add json module #8111
Add json module #8111
Conversation
CT Test Results 2 files 94 suites 34m 31s ⏱️ Results for commit c714e21. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial comments
Docs are a bit sparse :-)
Misses meta-data since 27.
But overall looks good to me.
lib/stdlib/test/json_SUITE.erl
Outdated
-ifdef(PROPER). | ||
-export([ | ||
property_string_roundtrip/1, | ||
property_integer_roundtrip/1, | ||
property_float_roundtrip/1, | ||
property_object_roundtrip/1, | ||
property_escape_all/1 | ||
]). | ||
|
||
-define(PROPER_NO_TRANS, true). | ||
-define(PROPER_NO_IMPORT_PARSE, true). | ||
-include_lib("proper/include/proper.hrl"). | ||
-endif. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, property tests are usually put in their own suite, using the ct_property_test
framework as described here. At least all the property tests for other modules in OTP that I know of are organized this way. For example, see stdlib/test/base64_property_test_SUITE.erl
and the corresponding stdlib/test/property_test/base64_prop.erl
.
This changes the string escaping implementation to read multiple bytes at once, and applies several other encoding optimisations. With those changes, in my benchmarks on an M1 mac, the new Btw, in the implementation of UTF8 validation using tuples and |
I can see such a function being useful in other scenarios. Perhaps it makes sense to export it as part of |
Unfortunately this function being efficient in here very much depends on it being placed in the same module as the caller allowing the compiler to analyse and optimise them together. I'm not convinced this would be particularly efficient as a standalone function. I'd prefer to focus on further optimising |
Would this help with UTF-8 validation in Cowboy and Bandit? |
I've pushed commits that tune the performance of decoder (and tiny changes to encoder). This also includes the change to decoder to remove the Current benchmark results for an M1 mac can be found in https://gist.github.com/michalmuskala/00e615f5de4305027abecffed45af07b The decoder is the fastest out of all libraries I've checked, except for I've also improved documentation and added some more examples. |
cowboy already does this - this is actually how I learned about this technique, though I'm pretty sure my implementation is more performant. |
Nice! I might have to revisit this, the VM has changed a lot this past decade. |
I've squashed the commits and rebased on top of latest master |
This implements the `json` module as specified in [EEP 68](https://github.com/erlang/eep/blob/master/eeps/eep-0068.md).
Add a separate API for streaming data, this is needed to make numbers work as expected since there is no way of knowing when a number is complete and doesn't continue in the next package. Allow the user to call decode_continue(NewBin, State) to complete the parsing. We also need 'end_of_input' argument to let the user signal that there is no more data in the case that stream only contained an integer or is an incomplete Json object.
And also add the copyright to the OTP copyright file.
Congratulations and thank you @michalmuskala! |
Hey @michalmuskala, Great work! Could you please share with us the code of the benchmark you ran? Thanks |
This implements the
json
module as specified in EEP 68.