Repository navigation
Speed up precise float text parsing (bump fast_float to v8.2.10) - #108205
Conversation
Header-only library; updates the float parser used by the precise `toFloat*`/`precise_float_parsing` path. v8.2.10 adds integer-parsing and digit-scan improvements over v8.2.3. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The parsing implementations (precise/fast/simple) and the heavy <fast_float/fast_float.h> include lived in readFloatText.h, so every translation unit that only calls these functions recompiled all of it (and re-parsed fast_float) on any change. Move the implementations and the fast_float include into readFloatText.cpp, leaving declarations plus explicit instantiations for BFloat16/Float32/Float64. No behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Precise path (precise_float_parsing=1, the fast_float-based parser):
- Replace the per-value dynamic_cast<ReadBufferFromMemory*> with a cheap
virtual ReadBuffer::isMemoryBuffer(), avoiding RTTI in the hot loop.
- Dispatch by the input length (known for free), shared by the no-copy
and copy paths:
* <= 19 chars -> fast_float::from_chars (cannot be too_many_digits,
so it never takes fast_float's re-parse path);
* long pure integer -> accumulate into unsigned __int128 (SWAR, 8 digits
(<= 38 digits) at a time) and convert, correctly rounded and far
cheaper than fast_float's big-integer path;
* otherwise -> fromCharsLong, a single-parse helper built on
fast_float's own primitives (no library fork) that
parses once with spans materialized, avoiding the
>19-significant-digit double parse.
Fast path (precise_float_parsing=0): accumulate 8 digits at a time via
SWAR in readUIntTextUpToNSignificantDigits instead of digit-by-digit.
The precise parser now matches or beats the fast (truncating) parser across
the practical range, including long integers, while staying correctly rounded.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ength For an integer with more than 38 significant digits (does not fit in unsigned __int128), build the parsed_number_string_t directly with a lean SWAR scan -- accumulate the first 19 significant digits, count the rest eight at a time -- and hand it to fast_float::from_chars_advanced. This avoids fast_float::parse_number_string accumulating every digit and then recomputing the mantissa from the first 19. Its result is returned as-is, including result_out_of_range (e.g. a >38-digit value that overflows Float32), instead of re-parsing through the slow path. Also SWAR the unsigned __int128 accumulation in the <= 38-digit integer path. Classify short vs long by the numeric token length, not the remaining buffer size: callers such as parseReadableSize pass a buffer whose end is past the number (e.g. "1.5 GiB"), so a short token in a larger buffer must still take the fast from_chars path. The selected parser still receives the real buffer end and consumes the whole token. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Around 120 boundary and corner inputs (zero/sign forms, dots, scientific notation, round-to-even ties near 2^52/2^53, full double range incl. subnormals/overflow/underflow, Float32 range and 2^24 ties, long integers crossing the 19- and 38-significant-digit dispatch boundaries, long fractions, leading zeros, whitespace, malformed input, and inf/nan spellings) parsed as Float32 and Float64 under both precise_float_parsing settings. Covers far more than the existing 02813_float_parsing. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [d801c4d] Summary: ❌
AI ReviewSummaryThis PR bumps Final VerdictStatus: ✅ Approve |
|
📊 Cloud Performance Report ✅ AI verdict: This PR rewrites the text-to-float parsing hot path (readFloatText) and moves it out of the header — it only affects converting text into floats during ingestion of text formats. ClickBench queries run over a table already loaded in native binary format, so Q4, Q15, and Q28 never exercise float-text parsing at SELECT time. The ~19% deltas on Q4/Q15 and the smaller borderline Q28 shift therefore can't be attributed to this change, and all three are downgraded to not-sure as off-path measurement variance rather than real query-path improvements. clickbenchFlagged queries (3 of 43)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
Moving the parsers into the .cpp exposed clang-tidy findings the header instantiations did not surface: - Extend the existing `clang-analyzer-*` NOLINT region to the whole file; the analyzer reaches `fast_float`'s `chars_format` flag-enum operators through the parse call sites, not just the include (same suppression as `IO/examples/read_float_perf.cpp`). - Drop the redundant `static` on two anonymous-namespace constexprs. - Initialize the SWAR `chunk`/`val` reads and value-initialize the three `from_chars_result_t` locals. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
This is exactly what lead me into this improvement. The fast algorithm is less less precise in Darwin + ARM than in Linux versions because |
It's fast method is less precise
Avoids using the fast methods which are going to fall anyway
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 245/403 (60.79%) · Uncovered code |
1a36e54
…v8.2.10 Speed up precise float text parsing (bump `fast_float` to v8.2.10)


Bumps
fast_floatfrom v8.2.3 to v8.2.10 and reworks the precise float textparser (
precise_float_parsing = 1) so it is as fast as, or faster than, thedefault (fast) parser on essentially every input.
Main changes:
readFloatTextPreciseImpl/readFloatTextFastImpland the heavy<fast_float/fast_float.h>include out ofreadFloatText.hinto the.cpp,so touching the parsers no longer rebuilds the world.
dynamic_castused to detect a memory buffer with avirtual
isMemoryBuffer, taking the no-copy path without RTTI.fast_float's re-scan: short numbers viafrom_chars;up to 38 digits via an
unsigned __int128SWAR accumulator with acorrectly-rounded conversion; longer integers by building the parsed-number
struct directly with wide reads instead of
fast_float's per-digittoo_many_digitsre-parse..,eor
Esends the token straight tofrom_chars(the integer fast paths cannotapply to a fraction/exponent).
fast_floatsource is left pristine (no fork); the long-integer path is builton top of its existing primitives.
Benchmarks
ThinLTO build, 16M strings per shape,
Float64, parse cost isolated bysubtracting a
sum(length(s))baseline; median ms, lower is better.Precise parser, master → this branch:
rand64(20-digit integers)longdigits(60-digit integers)int_bigint_smallrand32expratiofrac(long fractions)Large gains on long integers; the lone regression is long fractions (see below).
With this, the precise parser is faster than the default fast parser on every
shape except
frac(local non-LTO run, fast vs precise ms):int_smallint_bigrand32rand64expratiolongdigitsfracfracis ~19-20 significant-digit fractions, exactlyfast_float'stoo_many_digitsboundary. The fast path wins there (~1.06× on x86, ~1.32× onDarwin/ARM) only because it truncates the mantissa (~1 ULP off) while the precise
path rounds correctly; that cost is inherent at this digit count, and no dispatch
change closes it without giving up correct rounding.
The fast (default) path is kept at parity with master: an experiment that shared
the precise SWAR digit loop into it regressed short integers and ThinLTO did not
inline it back, so it was reverted. CI performance tests confirm that x86 results
remain stable, while ARM results see a slight improvement (around 10% in
random numbers).
Follow-up: with precise ahead on every shape but the inherent
fraccase, alater PR may enable
precise_float_parsingby default.04402_float_parsing_corner_casesis muted on Darwin: the fast parser's accuracytracks
long doublewidth (64-bit on Darwin/ARM, where it equalsdouble, vs80/128-bit on Linux), so a Linux-generated reference cannot match there.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up parsing of floating-point numbers from text with
precise_float_parsing = 1, making it as fast as or faster than the default parser on almost all inputs. Also bumps the bundledfast_floatlibrary to v8.2.10.Version info
26.7.1.359(included in26.7and later)