Optimize binary get_number implementation by reading multiple bytes at once#4391
Merged
nlohmann merged 7 commits intonlohmann:developfrom Nov 29, 2024
Merged
Optimize binary get_number implementation by reading multiple bytes at once#4391nlohmann merged 7 commits intonlohmann:developfrom
get_number implementation by reading multiple bytes at once#4391nlohmann merged 7 commits intonlohmann:developfrom
Conversation
b25a53f to
ea8b03d
Compare
🔴 Amalgamation check failed! 🔴The source code has not been amalgamated. @TianyiChen |
Owner
|
I like this idea! @TianyiChen any plans to continue working on this? |
fa2712d to
2362b3f
Compare
Contributor
Author
|
Sure, I have rebased the branch and added a from msgpack benchmark using C FILE. |
7c459d8 to
006d23a
Compare
Update input_adapters.hpp
72b20eb to
97fe5f2
Compare
895132a to
7acebd4
Compare
7acebd4 to
26cddc6
Compare
Owner
|
I could reproduce the benchmark results. Good job, thank you! BeforeAfter |
slowriot
pushed a commit
to slowriot/json
that referenced
this pull request
Jan 10, 2025
… at once (nlohmann#4391) * multibyte binary reader * wide_string_input_adapter fallback to get_character Update input_adapters.hpp * Update json.hpp * Add from msgpack test * Test for broken msgpack with stream, address some warnings * Reading binary number from wchar as an error, address warnings * Not casting float to int, it violates strict aliasing rule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves performance for
get_numberimplementation by reading multiple bytes at once, which saves calling overhead especially when interacting with file I/O. It addsget_elementsto input adapters and allow them to select more efficient underlying calls to read multiple bytes if availablePerformance for reading msgpack from C style
FILEdevelopbranch:
Questions:
get_elementsinwide_string_input_adapter, I encountered a compile error without it. If I don't implement it, tests are passing locally, which seems to make sense: ifwcharis used, likely the content has non-ASCII text and we won't want to interpret it as binary numbers, whereget_elementsis currently used. After looking into more UTF-8 decoding rules I think parsing binary from wide string doesn't make sense, and is making it an error.Pull request checklist
Read the Contribution Guidelines for detailed information.
include/nlohmanndirectory, runmake amalgamateto create the single-header filessingle_include/nlohmann/json.hppandsingle_include/nlohmann/json_fwd.hpp. The whole process is described here.Please don't
#ifdefs or other means.