Compare commits

...
3 Commits
Author SHA1 Message Date
Niels Lohmann 288b83fd6a Merge branch 'perf/binary-reader-byteswap' into perf/msgpack-scalar-runs
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-11-01 10:40:20 +01:00
Niels Lohmann 2ddee130c9 CBOR reader: inline get_cbor_float() and always inline get() instead
The never-inlined get_cbor_float() costs a call for every float read
from input without bulk access: reading canada.json from CBOR through a
FILE* became 5.6 % slower on Apple clang in the benchmark suite. The
helper existed only because GCC 13 stopped inlining the stream adapter's
get_character() into parse_cbor_internal. Always inlining
binary_reader::get() fixes that as well.

callgrind, all binary formats on buffer, std::istringstream and FILE*
input (canada and citm_catalog): GCC 13 0.986-1.003, GCC 16 0.994-1.006,
Clang 23 identical. Apple clang suite: FromBinaryFile/cbor/canada 0.939,
geomean of the 53 binary reader rows 0.998.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-11-01 10:40:05 +01:00
Niels Lohmann 1ee958e49c MessagePack tests: assign the parsed value instead of casting it to void
GCC (ci_test_gcc) reports -Werror=unused-result for
static_cast<void>(json::from_msgpack(...)): a cast to void does not silence
warn_unused_result on GCC. Assign to a json, as the other tests in the file do.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-11-01 03:19:32 +01:00
3 changed files with 16 additions and 8 deletions

No files matched your search

@@ -1148,10 +1148,8 @@ class binary_reader
}
}
/// read a single- or double-precision float (kept out of
/// parse_cbor_value, which is inlined into parse_cbor_internal)
/// read a single- or double-precision float
template<typename NumberType>
JSON_HEDLEY_NEVER_INLINE
bool get_cbor_float()
{
NumberType number{};
@@ -4364,7 +4362,12 @@ class binary_reader
`char_traits<char_type>::eof()` in that case.
@return character read from the input
@note always inlined: GCC otherwise stops inlining the stream adapter's
get_character() into parse_cbor_internal once that function grows
(+0.45 % instructions for CBOR from a std::istringstream with GCC 13)
*/
JSON_HEDLEY_ALWAYS_INLINE
char_int_type get()
{
++chars_read;
+6 -3
View File
@@ -18925,10 +18925,8 @@ class binary_reader
}
}
/// read a single- or double-precision float (kept out of
/// parse_cbor_value, which is inlined into parse_cbor_internal)
/// read a single- or double-precision float
template<typename NumberType>
JSON_HEDLEY_NEVER_INLINE
bool get_cbor_float()
{
NumberType number{};
@@ -22141,7 +22139,12 @@ class binary_reader
`char_traits<char_type>::eof()` in that case.
@return character read from the input
@note always inlined: GCC otherwise stops inlining the stream adapter's
get_character() into parse_cbor_internal once that function grows
(+0.45 % instructions for CBOR from a std::istringstream with GCC 13)
*/
JSON_HEDLEY_ALWAYS_INLINE
char_int_type get()
{
++chars_read;
+4 -2
View File
@@ -2275,7 +2275,8 @@ TEST_CASE("MessagePack arrays of scalars from contiguous and non-contiguous inpu
std::string bytewise_error;
try
{
static_cast<void>(json::from_msgpack(contiguous));
json _;
_ = json::from_msgpack(contiguous);
}
catch (const json::parse_error& e)
{
@@ -2283,7 +2284,8 @@ TEST_CASE("MessagePack arrays of scalars from contiguous and non-contiguous inpu
}
try
{
static_cast<void>(json::from_msgpack(bytewise.begin(), bytewise.end()));
json _;
_ = json::from_msgpack(bytewise.begin(), bytewise.end());
}
catch (const json::parse_error& e)
{