Skip to content

Convert the floats of json_view from the digit layout - #5626

Closed
nlohmann wants to merge 5 commits into
json-view/14-view-comparefrom
json-view/14b-view-float-layout
Closed

nlohmann wants to merge 5 commits into
json-view/14-view-comparefrom
json-view/14b-view-float-layout

Conversation

@nlohmann

@nlohmann nlohmann commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

Part of the stack for the zero-copy view (#5295).

Summary

While parsing, the view records where the integer digits, the fraction digits, and the exponent of a float token are. For floats and doubles with at most 19 digits, the value is now read from that layout:

Both round correctly, so the values are those of parse(). Longer tokens, and long double, keep the library's conversion of the whole token.

get<double>(), materialize(), dump(), and the comparisons all use it.

Benchmarks

Traversing canada.json (111,000 floats, every number converted): 0.95 → 1.29 GB/s. The baseline already includes #5738, whose converter the view uses before this PR.

Tests

Tokens around the limits (19 and 20 digits, 2^53, 10^22, underflow, and those of float) join the bit-for-bit comparison with parse().

Public API

No change.


Written by Claude Code.

🤖 Generated with Claude Code

@nlohmann
nlohmann added this pull request to stack #5636 September 29, 2026 14:20
@github-actions

Copy link
Copy Markdown

🔴 Amalgamation check failed! 🔴

The source code has not been amalgamated and/or formatted correctly, or BUILD.bazel is out of date.

@nlohmann
nlohmann removed this pull request from stack #5636 September 30, 2026 13:19
@nlohmann
nlohmann force-pushed the json-view/14b-view-float-layout branch from 921b664 to cbd93ff Compare September 30, 2026 13:20
@nlohmann
nlohmann added this pull request to stack #5739 September 30, 2026 13:21
@nlohmann
nlohmann force-pushed the json-view/14-view-compare branch from 4f00cac to adbc848 Compare September 30, 2026 15:34
@nlohmann
nlohmann force-pushed the json-view/14b-view-float-layout branch 3 times, most recently from 1b49a60 to 7a97dc0 Compare September 30, 2026 18:06
@nlohmann nlohmann added the review needed It would be great if someone could review the proposed changes. label Sep 30, 2026
@nlohmann
nlohmann marked this pull request as ready for review September 30, 2026 18:17
The parser records where the integer digits, the fraction digits, and the
exponent of a float token are. For floats and doubles with at most 19
digits, the value is now read from that layout: the digits eight at a time,
without scanning the token, and rounded by the library's conversion core
(detail::decimal_to_float(): Clinger's fast path where both operands are
exact, else the Eisel-Lemire algorithm, which needs no fallback for up to 19
digits). It rounds correctly, so the values are those of parse(); other
tokens and types keep the library's conversion of the whole token.

get<double>(), materialize(), dump(), and comparisons use it. Traversing
canada.json (111,000 floats, every number converted): 0.95 -> 1.29 GB/s.

Tests add tokens around the limits (19 and 20 digits, 2^53, 10^22, and
those of float) to the bit-for-bit comparison with parse().

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
@nlohmann
nlohmann force-pushed the json-view/14-view-compare branch from c2792eb to b992e1f Compare September 30, 2026 19:15
@nlohmann
nlohmann force-pushed the json-view/14b-view-float-layout branch from 7a97dc0 to ecf9df7 Compare September 30, 2026 19:15
…t-layout

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
…t-layout

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
…t-layout

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
…HEAD

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
@nlohmann
nlohmann removed this pull request from stack #5739 October 6, 2026 09:26
@nlohmann

nlohmann commented Oct 6, 2026

Copy link
Copy Markdown
Owner Author

The zero-copy view stack (#5295) was rebased onto develop and regrouped from 20 PRs into 10, one squashed commit each. The changes of this PR are now in #5624; its review comments stay here for reference.


Written by Claude Code.

@nlohmann nlohmann closed this Oct 6, 2026
@nlohmann
nlohmann deleted the json-view/14b-view-float-layout branch October 12, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L review needed It would be great if someone could review the proposed changes. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant