Repository navigation
Conversation
nlohmann
added this pull request to stack #5636
September 29, 2026 14:20
This was referenced Sep 29, 2026
Owner
Author
|
CI fix for this PR (commit 977bb1b, plus all lower fixes merged in). CI had not run yet; this was found locally with
Verified: — posted by Claude Code on behalf of @nlohmann |
nlohmann
removed this pull request from stack #5636
September 30, 2026 13:19
nlohmann
force-pushed
the
json-view/24-view-token-digits
branch
from
September 30, 2026 13:20
f4a72e4 to
ba55e27
Compare
nlohmann
added this pull request to stack #5739
September 30, 2026 13:21
nlohmann
force-pushed
the
json-view/24-view-token-digits
branch
from
September 30, 2026 15:34
ba55e27 to
8ce7529
Compare
nlohmann
force-pushed
the
json-view/23-zmij
branch
from
September 30, 2026 15:34
3336423 to
076ec09
Compare
nlohmann
force-pushed
the
json-view/24-view-token-digits
branch
2 times, most recently
from
September 30, 2026 18:06
85e1a37 to
badc20d
Compare
nlohmann
marked this pull request as ready for review
September 30, 2026 18:16
dump() writes a float token of at most 15 significant digits from its
digits, without converting it to a double and back: two decimals of at
most 15 digits are farther apart than the rounding interval of a
normal double (the argument behind DBL_DIG), so the token's digits are
the shortest ones of its double, which the library's conversion (Zmij)
writes. The exponent must keep the value away from subnormals and
overflow. Longer tokens are converted from the digits already read.
Doubles are written into the output directly instead of through a
local buffer. With NEON, the fixed layouts ("12.5", "0.001", "100.0")
are put together in vector registers by a table lookup of the digit
bytes: the portable layout copies the digits through a buffer at
another offset, and a load that spans several recent stores waits
until they reach the cache.
dump() of float-heavy documents: numbers -69%, marine_ik -62%,
mesh.pretty -34%, canada (mostly 16 or 17 digits) -14%.
Tests: 20,000 float tokens of 1 to 17 significant digits in every
spelling (point, exponent, leading and trailing zeros, sign), from about
1e-320 to 1e300, written as json::dump() writes them. On AArch64 they
check the NEON layout; x86 and JSON_VIEW_NO_SIMD use the library's.
Other float types, now the only ones on the general path, are tested
with non-finite values set by edits (written as null).
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
GCC -Werror=useless-cast on Linux x86-64 rejected static_cast<std::size_t>(tokens() % n): std::mt19937_64 yields std::uint_fast64_t, which is std::size_t there. Draw the numbers through a lambda that casts a named std::uint64_t, which also makes the conversions for std::string's count explicit where std::size_t is 32 bits wide. The sequence of draws is unchanged. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
nlohmann
force-pushed
the
json-view/23-zmij
branch
from
September 30, 2026 19:19
165bdff to
0a97d94
Compare
nlohmann
force-pushed
the
json-view/24-view-token-digits
branch
from
September 30, 2026 19:19
badc20d to
414d378
Compare
🔴 Amalgamation check failed! 🔴The source code has not been amalgamated and/or formatted correctly, or |
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
nlohmann
removed this pull request from stack #5739
October 6, 2026 09:26
Owner
Author
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.
Part of the stack for the zero-copy view (#5295). Depends on the previous PR (shortest doubles with Żmij).
Summary
json_view::dump()writes a float token of at most 15 significant digits from its digits, without converting it to a double and back. The output is unchanged: it is whatjson::dump()writes for the same value.DBL_DIG. So the token's digits, without trailing zeros, are the shortest digits of its double. The library now writes exactly those (Żmij); with Grisu2 this would not hold.decimal_to_float()(Speed up the lexer: own float parser, string scan, and \u table #5738), so the token is not read twice.12.5,0.001,100.0) are put together in vector registers by a table lookup of the digit bytes, as in the prototype. The library's portable layout copies the digits through a buffer at another offset, and a load that spans several recent stores waits until they reach the cache. x86 andJSON_VIEW_NO_SIMDuse the library's layout.Benchmarks
json_view::dump(), before vs. after this PR, on Apple M1 (best of 7 alternating processes):canada's tokens mostly have 16 or 17 digits, so they are converted; its gain comes from writing in place and from the NEON layout.
Tests
e/Eand signs, leading zeros (0.000123), trailing zeros, and negative values, from about 1e−320 to 1e300 (subnormals included).json_view::dump()must equaljson::dump()of the same text.JSON_VIEW_NO_SIMD, the library's layout.Public API
No change.
Written by Claude Code.
🤖 Generated with Claude Code