Skip to content

Commit 70ee13b

Browse files
committed
strconv: replace Ryu ftoa with Dragonbox
Dragonbox is a faster ftoa algorithm that provides the same guarantees as Ryu: round-trip conversion, shortest length, and correct rounding. The author of the reference implementation has agreed to distribute this file under Go's BSD-style license. The new implementation has been fuzz-tested against the current Ryu implementation in addition to the existing test suite. Benchmarks show at least ~15-20% performance improvement. Dragonbox only supports shortest-precision conversion, so we continue to use Ryu-printf for fixed precision. The following shows the relevant output from benchstat, excluding fixed-precision cases. Full benchmark results and plots are available at: https://github.com/taichimaeda/dragonbox-bench/ goos: darwin goarch: arm64 pkg: strconv cpu: Apple M1 Ryu: BenchmarkFormatFloat/Decimal-8 36197865 31.45 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/Float-8 26408643 45.49 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/Exp-8 23845756 49.87 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/NegExp-8 25607784 47.04 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/LongExp-8 26079632 46.16 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/Big-8 24082401 49.99 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/BinaryExp-8 42700762 27.90 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/32Integer-8 38270085 31.41 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/32ExactFraction-8 26591202 45.31 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/32Point-8 27870975 43.20 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/32Exp-8 26127472 45.93 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/32NegExp-8 26843410 44.70 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/32Shortest-8 31629616 37.95 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/Slowpath64-8 25230336 47.78 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/SlowpathDenormal64-8 27206694 43.22 ns/op 0 B/op 0 allocs/op Dragonbox: BenchmarkFormatFloat/Decimal-8 39320097 30.38 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/Float-8 28416686 42.02 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/Exp-8 37673996 31.86 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/NegExp-8 38569448 31.11 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/LongExp-8 27570123 43.34 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/Big-8 30569094 38.95 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/BinaryExp-8 43578852 28.05 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/32Integer-8 52877412 22.81 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/32ExactFraction-8 40459780 29.81 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/32Point-8 36037794 33.68 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/32Exp-8 47398902 25.32 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/32NegExp-8 47989363 25.04 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/32Shortest-8 43502100 27.76 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/Slowpath64-8 26418043 45.49 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/SlowpathDenormal64-8 28887122 41.43 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/ShorterIntervalCase32-8 47092680 25.95 ns/op 0 B/op 0 allocs/op BenchmarkFormatFloat/ShorterIntervalCase64-8 42481884 27.65 ns/op 0 B/op 0 allocs/op Fixes #74886
1 parent 8377ada commit 70ee13b

File tree

4 files changed

+1521
-114
lines changed

4 files changed

+1521
-114
lines changed

0 commit comments

Comments
 (0)