Normalize trailing decimal zeros before bigint comparison
perfloop/fast_float · Inefficient Algorithm
https://perfloop.ai/t/oss/case_xwm9h4yejp
Verdict
VERIFIED · settled 2026-11-14
What happened: The paired measurements met the required improvement.
Hypothesis
`digit_comp` derives `sci_exp` from the original parsed coefficient at digit_comparison.h:437-438, then `parse_mantissa` reconstructs every retained digit into a bigint (255-337) and line 444 derives the decimal scale as `sci_exp + 1 - digits`. If a coefficient ends in z zero digits, parsing only the prefix through its last nonzero digit reduces both the bigint coefficient and `digits` by z; line 444 increases the scale by z, preserving the exact decimal value. The current path instead builds zero limbs up to `binary_format<double>::max_digits()` (769) and can enter `negative_digit_comp` with that unnormalized representation.
The indexed incoming-call check found `from_chars_advanced` calling this target at parse_number.h:286, where the caller documents the `am.power2 < 0` route as very uncommon. The cadence is therefore once per unresolved long conversion, not per ordinary parse. A local `ff_trim_zero_diff` C++ differential generated 37 real `too_many_digits` cases for which `compute_float(m)` differed from `compute_float(m + 1)`; the current target and a version with only logical terminal-zero span trimming returned identical adjusted mantissas. A separate direct-target calibration used a 735-character coefficient with a 30-digit nonzero core, 700 terminal zeros, and a compensated exponent: across 50,000 calls it reported about 80-81 ms for the current target versus 19 ms for the trimmed variant. Those are source-local synthetic checks, not evidence of production input frequency or end-to-end latency.
A case session should exercise the public `from_chars` entry with actual unresolved long inputs while sweeping nonzero-core length, zero-suffix length (including 0, below/above the crossover, 769+, and much longer), integer versus fraction suffix placement, and explicit exponents. It should differentially verify result bits, pointer, and error code, measure target and end-to-end CPU/latency, and use branch/input telemetry to establish whether long zero-padded fields occur often enough to matter. This is local normalization after the current handoff and does not replace the already-published parse/reparse-span fix.
Change to test: Inside `digit_comp`, add a logical trailing-zero normalization for the significant-digit spans before calling `parse_mantissa`: when the final fraction or integer digit is zero, find the last nonzero digit by scanning fraction then integer backward, and pass shortened logical ends to the mantissa parser only past a measured crossover. Keep `sci_exp` from the original parsed number so the existing `sci_exp + 1 - digits` calculation absorbs the removed powers of ten. Retain the current spans for no suffix and all-zero inputs, and preserve the current truncation and exact-rounding behavior for any nonzero suffix.
Where it lives
perfloop/fast_float · include/fast_float/parse_number.h
Evidence
from_chars conformance decimals · 15 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ordinary_ascii64_MiB_per_s |
162.8 |
174.5 |
+7.1% (+11.55) |
+11.03 to +12.76 |
gain > 0; gain > 0.05 × |baseline median|; arm medians separated |
PASSED |
ordinary_ascii32_MiB_per_s |
450.7 |
463.5 |
+2.7% (+12.19) |
+8.69 to +19.15 |
loss ≤ 0.05 × |baseline median| |
PASSED |
from_chars round and scaled decimals · 15 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
round_ascii64_MiB_per_s |
222.4 |
222.5 |
+0.03 |
−1.05 to +0.56 |
loss ≤ 0.05 × |baseline median| |
PASSED |
round_ascii32_MiB_per_s |
361.2 |
376.2 |
+4.2% (+15.02) |
+13.77 to +16.41 |
loss ≤ 0.05 × |baseline median| |
PASSED |
fraction_ascii64_MiB_per_s |
322 |
422.3 |
+31.1% (+100.3) |
+99.08 to +101.1 |
loss ≤ 0.05 × |baseline median| |
PASSED |
fraction_ascii32_MiB_per_s |
693.4 |
692.7 |
−0.52 |
−3.22 to +1.94 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wei_ascii64_MiB_per_s |
393.7 |
394.8 |
+1.48 |
−0.92 to +3.67 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wei_ascii32_MiB_per_s |
425.2 |
425.9 |
+0.68 |
−1.41 to +3.63 |
loss ≤ 0.05 × |baseline median| |
PASSED |
fixed_ascii64_MiB_per_s |
327.7 |
344.3 |
+5% (+16.34) |
+14.7 to +18.45 |
loss ≤ 0.05 × |baseline median| |
PASSED |
fixed_ascii32_MiB_per_s |
780.8 |
787.6 |
+0.8% (+6.37) |
+2.89 to +9.28 |
loss ≤ 0.05 × |baseline median| |
PASSED |
from_chars zero-suffix boundaries · 15 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
long_ascii64_MiB_per_s |
494.8 |
811.9 |
+64.1% (+317.3) |
+315.1 to +318.9 |
loss ≤ 0.05 × |baseline median| |
PASSED |
long_ascii32_MiB_per_s |
903.3 |
893.9 |
−1% (−9.3) |
−10.16 to −7.34 |
loss ≤ 0.05 × |baseline median| |
PASSED |
short_ascii64_MiB_per_s |
298.1 |
298.8 |
+0.41 |
−1.2 to +2.78 |
loss ≤ 0.05 × |baseline median| |
PASSED |
short_ascii32_MiB_per_s |
845 |
835.6 |
−1.1% (−9.38) |
−12.31 to −7.24 |
loss ≤ 0.05 × |baseline median| |
PASSED |
medium_ascii64_MiB_per_s |
295.5 |
306 |
+3.4% (+9.93) |
+8.49 to +12.88 |
loss ≤ 0.05 × |baseline median| |
PASSED |
medium_ascii32_MiB_per_s |
879.9 |
870.3 |
−1.1% (−9.56) |
−10.03 to −7.36 |
loss ≤ 0.05 × |baseline median| |
PASSED |
from_chars dense and sparse decimals · 16 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
dense_ascii64_MiB_per_s |
816.5 |
813.1 |
−0.4% (−3.205) |
−5.9 to −1.89 |
loss ≤ 0.05 × |baseline median| |
PASSED |
dense_ascii32_MiB_per_s |
919 |
908.9 |
−1.1% (−10.22) |
−12.29 to −9.84 |
loss ≤ 0.05 × |baseline median| |
PASSED |
sparse100000_ascii64_MiB_per_s |
385.5 |
385.5 |
+0.01 |
−0.04 to +0.05 |
loss ≤ 0.05 × |baseline median| |
PASSED |
sparse100000_ascii32_MiB_per_s |
393.5 |
393.5 |
0 |
−0.01 to +0.02 |
loss ≤ 0.05 × |baseline median| |
PASSED |
sparse1000000_ascii64_MiB_per_s |
384.4 |
384.4 |
+0.04 |
−0.67 to +0.6 |
loss ≤ 0.05 × |baseline median| |
PASSED |
sparse1000000_ascii32_MiB_per_s |
390.8 |
390.7 |
−0.15 |
−0.48 to +0.4 |
loss ≤ 0.05 × |baseline median| |
PASSED |
from_chars canada decimals · 16 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
canada_ascii64_MiB_per_s |
1498 |
1489 |
−0.6% (−8.925) |
−12.93 to −2.79 |
loss ≤ 0.05 × |baseline median| |
PASSED |
canada_ascii32_MiB_per_s |
1507 |
1489 |
−1.3% (−18.85) |
−27.71 to −5.76 |
loss ≤ 0.05 × |baseline median| |
PASSED |
from_chars short and trimmed coefficients · 48 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
minimum_int_ns_per_call |
126.3 |
128.5 |
+1.959 |
−0.951 to +5.162 |
loss ≤ 0.05 × |baseline median| |
PASSED |
minimum_frac_ns_per_call |
110.5 |
111 |
+0.7435 |
−1.574 to +2.65 |
loss ≤ 0.05 × |baseline median| |
PASSED |
trim_int_ns_per_call |
162.5 |
163.5 |
+1.437 |
−2.392 to +6.225 |
loss ≤ 0.05 × |baseline median| |
PASSED |
trim_frac_ns_per_call |
121.5 |
121.3 |
−0.8375 |
−4.366 to +1.749 |
loss ≤ 0.05 × |baseline median| |
PASSED |
from_chars split suffix and digit_comp · 134 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
trim_cross_ns_per_call |
171.4 |
175.9 |
+4.433 |
−2.694 to +8.356 |
loss ≤ 0.05 × |baseline median| |
PASSED |
float_half_ns_per_call |
126.4 |
119.4 |
−5.2% (−6.601) |
−10.18 to −3.11 |
loss ≤ 0.05 × |baseline median| |
PASSED |
target_ns_per_call |
68.94 |
68.77 |
+0.152 |
−1.926 to +1.756 |
loss ≤ 0.05 × |baseline median| |
PASSED |
minimum_positive_ns_per_call |
93.91 |
96 |
+1.185 |
−0.732 to +3.466 |
loss ≤ 0.05 × |baseline median| |
PASSED |
from_chars minimal decimal inputs · 39 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
minimum_negative_ns_per_call |
120.9 |
122.9 |
+1.855 |
−1.645 to +5.786 |
loss ≤ 0.05 × |baseline median| |
PASSED |
minimum_fraction_only_ns_per_call |
105.8 |
106.5 |
+0.888 |
−3.331 to +4.265 |
loss ≤ 0.05 × |baseline median| |
PASSED |
minimum_decimal_ns_per_call |
106.9 |
107.4 |
+0.557 |
−3.582 to +3.199 |
loss ≤ 0.05 × |baseline median| |
PASSED |
minimum_trim_fraction_ns_per_call |
116.6 |
115.8 |
−0.984 |
−4.136 to +2.072 |
loss ≤ 0.05 × |baseline median| |
PASSED |
from_chars empty fraction and float integers · 35 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
minimum_trim_decimal_ns_per_call |
121.1 |
117.1 |
−3.8% (−4.624) |
−11.73 to −1.891 |
loss ≤ 0.05 × |baseline median| |
PASSED |
empty_fraction_ns_per_call |
106.6 |
108 |
+1.27 |
−3.799 to +4.427 |
loss ≤ 0.05 × |baseline median| |
PASSED |
float_min_positive_ns_per_call |
95.67 |
95.55 |
−0.754 |
−3.95 to +3.231 |
loss ≤ 0.05 × |baseline median| |
PASSED |
float_min_negative_ns_per_call |
123.8 |
123.9 |
+0.387 |
−2.814 to +3.122 |
loss ≤ 0.05 × |baseline median| |
PASSED |
from_chars minimal float decimals · 35 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
float_min_fraction_ns_per_call |
103.9 |
103.8 |
+0.081 |
−3.675 to +4.504 |
loss ≤ 0.05 × |baseline median| |
PASSED |
float_min_decimal_ns_per_call |
102 |
102.1 |
−0.062 |
−2.534 to +3.26 |
loss ≤ 0.05 × |baseline median| |
PASSED |
float_trim_fraction_ns_per_call |
112.6 |
113 |
−0.173 |
−2.727 to +2.134 |
loss ≤ 0.05 × |baseline median| |
PASSED |
float_trim_decimal_ns_per_call |
116.2 |
110.7 |
−4.5% (−5.246) |
−7.103 to −2.301 |
loss ≤ 0.05 × |baseline median| |
PASSED |
Checks: 3 of 3 passed. Verification: no defect found.
Timeline
2026-07-31· Case opened2026-08-04· PR opened2026-10-25· Case closed