This PR improves performance for get_number implementation by reading multiple bytes at once, which saves calling overhead especially when interacting with file I/O. It adds get_elements to input adapters and allow them to select more efficient underlying calls to read multiple bytes if available
for get_elements in wide_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: if wchar is used, likely the content has non-ASCII text and we won't want to interpret it as binary numbers, where get_elements is currently used. I am not sure are we expected to fallback to reading each char one-by-one or doing something else. Currently it just falls back to the get_character method.
[ ] The source code is amalgamated; that is, after making changes to the sources in the include/nlohmann directory, run make amalgamate to create the single-header files single_include/nlohmann/json.hpp and single_include/nlohmann/json_fwd.hpp. The whole process is described here.
Please don't
The C++11 support varies between different compilers and versions. Please note the list of supported compilers. Some compilers like GCC 4.7 (and earlier), Clang 3.3 (and earlier), or Microsoft Visual Studio 13.0 and earlier are known not to work due to missing or incomplete C++11 support. Please refrain from proposing changes that work around these compiler's limitations with #ifdefs or other means.
Specifically, I am aware of compilation problems with Microsoft Visual Studio (there even is an issue label for this kind of bug). I understand that even in 2016, complete C++11 support isn't there yet. But please also understand that I do not want to drop features or uglify the code just to make Microsoft's sub-standard compiler happy. The past has shown that there are ways to express the functionality such that the code compiles with the most recent MSVC - unfortunately, this is not the main objective of the project.
Please refrain from proposing changes that would break JSON conformance. If you propose a conformant extension of JSON to be supported by the library, please motivate this extension.
Please do not open pull requests that address multiple issues.
coverage: 99.951% (-0.05%) from 100.0%
when pulling ea8b03d86452f42b8512144e6fd68020e9d7cd82 on TianyiChen:msgpack-int
into 8c391e04fe4195d8be862c97f38cfe10e2a3472e on nlohmann:develop.
This PR improves performance for
get_number
implementation by reading multiple bytes at once, which saves calling overhead especially when interacting with file I/O. It addsget_elements
to input adapters and allow them to select more efficient underlying calls to read multiple bytes if availablePerformance for reading msgpack from C style
FILE
develop
branch:
Questions:
for
get_elements
inwide_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: ifwchar
is used, likely the content has non-ASCII text and we won't want to interpret it as binary numbers, whereget_elements
is currently used. I am not sure are we expected to fallback to reading each char one-by-one or doing something else. Currently it just falls back to theget_character
method.the current benchmark doesn't contain one which reads/writes binary from file, so the benchmark won't change with the PR unless those tests are included, shall we add them like https://github.com/nlohmann/json/discussions/4389#discussioncomment-9684116 ?
Pull request checklist
Read the Contribution Guidelines for detailed information.
include/nlohmann
directory, runmake amalgamate
to create the single-header filessingle_include/nlohmann/json.hpp
andsingle_include/nlohmann/json_fwd.hpp
. The whole process is described here.Please don't
#ifdef
s or other means.