Keep chars_format::javascript out of the common hot path - #410
Merged
Merged
Conversation
8.3.0 added the ECMAScript leading-zero rule as a runtime test on fmt inside
parse_number_string, so unlike basic_json_fmt its error returns and Annex B
octal scan land in the parser body that every from_chars instantiation
force-inlines. from_chars_caller<double>::call grew from 935 to 1031
instructions and other formats lost about 3% on short inputs.
Make the rule a compile-time parameter of the parser body, selected once at the
entry point, and take chars_format::javascript out to a cold conversion before
anything else is live so the branch is a tail call. parse_number_string keeps
its signature and behaviour.
benchmarks/benchmark.cpp, Intel Xeon 6975P-C, clang 22.1.8, cycles per float,
best of 7:
canada.txt mesh.txt
8.2.10 47.03 24.78
8.3.0 47.34 26.08
this 46.28 24.86
Member
|
@Algunenano This looks good, running tests, and then I will merge. |
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.
chars_format::javascript, new in 8.3.0, adds its ECMAScript leading-zero rule as a runtime test onfmtinsideparse_number_string. Unlikebasic_json_fmt, which is a template parameter and compiles away, this one cannot: its two error returns and the Annex B octal scan land in the parser body that everyfrom_charsinstantiation force-inlines, andfmthas to stay live across the integer scan.This turned up while reviewing the v8.3.0 bump in ClickHouse (ClickHouse/ClickHouse#121383), which only ever passes
chars_format::general. The bump alone cost about 3% on text float parsing.The fix makes the rule a compile-time parameter of the parser body.
parse_number_stringkeeps its signature and behaviour: it tests the format once and routes to a cold, never-inlined javascript instantiation, so callers that use it directly are unaffected.from_chars_float_advancedleaves for a coldfrom_chars_float_javascriptas its first statement, before anything else is live, so it compiles to a tail call. Placement matters here: any later, andoptionsstays live across the parse and the hot frame picks up two extra spill pairs, which costs as much as the original problem.Measurements
Intel Xeon 6975P-C (Granite Rapids), clang 22.1.8.
ClickHouse, instructions in
from_chars_caller<double>::call: 935 on v8.2.10, 1031 on v8.3.0, 944 on this branch.ClickHouse, parsing a 20M row text column of
Float64,perf statfor the whole run:benchmarks/benchmark.cpp, cycles per float, best of 7:ctestis green with clang 22 and with gcc in C++20 mode.clang-format-17 --style=filereports no changes.