-
Notifications
You must be signed in to change notification settings - Fork 18.4k
strconv: replace Ryu ftoa with Dragonbox #75195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This PR (HEAD: 379512d) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/700075. Important tips:
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
This PR (HEAD: 27788a0) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/700075. Important tips:
|
Message from Taichi Maeda: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
This PR (HEAD: c7383b6) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/700075. Important tips:
|
Message from Sean Liao: Patch Set 3: Commit-Queue+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
Message from Go LUCI: Patch Set 3: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2025-08-31T11:23:34Z","revision":"2e9287e9c4d85e395c4eab51818a0b29472ecee4"} Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
Message from Sean Liao: Patch Set 3: -Commit-Queue Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
Message from Go LUCI: Patch Set 3: This CL has passed the run Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
Message from Go LUCI: Patch Set 3: LUCI-TryBot-Result+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
c7383b6
to
70ee13b
Compare
This PR (HEAD: 70ee13b) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/700075. Important tips:
|
Message from Taichi Maeda: Patch Set 5: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
Message from Taichi Maeda: Patch Set 5: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
Message from Sean Liao: Patch Set 6: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
70ee13b
to
6699b0f
Compare
This PR (HEAD: 6699b0f) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/700075. Important tips:
|
Message from Taichi Maeda: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
Message from Taichi Maeda: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
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. Full benchmark results and plots are available at: https://github.com/taichimaeda/dragonbox-bench/ goos: darwin goarch: arm64 pkg: strconv cpu: Apple M1 │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ FormatFloat/Decimal-8 32.71n ± 14% 31.89n ± 12% ~ (p=0.165 n=10) FormatFloat/Float-8 45.54n ± 1% 42.48n ± 0% -6.70% (p=0.000 n=10) FormatFloat/Exp-8 50.06n ± 0% 32.27n ± 1% -35.54% (p=0.000 n=10) FormatFloat/NegExp-8 47.15n ± 1% 31.33n ± 0% -33.56% (p=0.000 n=10) FormatFloat/LongExp-8 46.15n ± 1% 43.66n ± 0% -5.38% (p=0.000 n=10) FormatFloat/Big-8 50.02n ± 0% 39.36n ± 0% -21.31% (p=0.000 n=10) FormatFloat/BinaryExp-8 27.89n ± 0% 27.88n ± 1% ~ (p=0.798 n=10) FormatFloat/32Integer-8 31.41n ± 0% 23.00n ± 3% -26.79% (p=0.000 n=10) FormatFloat/32ExactFraction-8 44.93n ± 1% 29.91n ± 0% -33.43% (p=0.000 n=10) FormatFloat/32Point-8 43.22n ± 1% 33.82n ± 0% -21.74% (p=0.000 n=10) FormatFloat/32Exp-8 45.91n ± 0% 25.48n ± 0% -44.50% (p=0.000 n=10) FormatFloat/32NegExp-8 44.66n ± 0% 25.12n ± 0% -43.76% (p=0.000 n=10) FormatFloat/32Shortest-8 37.96n ± 0% 27.83n ± 1% -26.68% (p=0.000 n=10) FormatFloat/Slowpath64-8 47.74n ± 2% 45.85n ± 0% -3.96% (p=0.000 n=10) FormatFloat/SlowpathDenormal64-8 42.78n ± 1% 41.46n ± 0% -3.07% (p=0.000 n=10) FormatFloat/ShorterIntervalCase32-8 25.49n ± 2% FormatFloat/ShorterIntervalCase64-8 27.72n ± 1% geomean 41.95n 31.89n -22.11% Fixes golang#74886
6699b0f
to
a6241f7
Compare
This PR (HEAD: a6241f7) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/700075. Important tips:
|
Message from Taichi Maeda: Patch Set 8: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
Message from Emmanuel Odeke: Patch Set 8: Run-TryBot+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
Message from Gopher Robot: Patch Set 8: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
Message from Taichi Maeda: Patch Set 8: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/700075. |
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. Full benchmark
results and plots are available at:
https://github.com/taichimaeda/dragonbox-bench/
goos: darwin
goarch: arm64
pkg: strconv
cpu: Apple M1
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
FormatFloat/Decimal-8 32.71n ± 14% 31.89n ± 12% ~ (p=0.165 n=10)
FormatFloat/Float-8 45.54n ± 1% 42.48n ± 0% -6.70% (p=0.000 n=10)
FormatFloat/Exp-8 50.06n ± 0% 32.27n ± 1% -35.54% (p=0.000 n=10)
FormatFloat/NegExp-8 47.15n ± 1% 31.33n ± 0% -33.56% (p=0.000 n=10)
FormatFloat/LongExp-8 46.15n ± 1% 43.66n ± 0% -5.38% (p=0.000 n=10)
FormatFloat/Big-8 50.02n ± 0% 39.36n ± 0% -21.31% (p=0.000 n=10)
FormatFloat/BinaryExp-8 27.89n ± 0% 27.88n ± 1% ~ (p=0.798 n=10)
FormatFloat/32Integer-8 31.41n ± 0% 23.00n ± 3% -26.79% (p=0.000 n=10)
FormatFloat/32ExactFraction-8 44.93n ± 1% 29.91n ± 0% -33.43% (p=0.000 n=10)
FormatFloat/32Point-8 43.22n ± 1% 33.82n ± 0% -21.74% (p=0.000 n=10)
FormatFloat/32Exp-8 45.91n ± 0% 25.48n ± 0% -44.50% (p=0.000 n=10)
FormatFloat/32NegExp-8 44.66n ± 0% 25.12n ± 0% -43.76% (p=0.000 n=10)
FormatFloat/32Shortest-8 37.96n ± 0% 27.83n ± 1% -26.68% (p=0.000 n=10)
FormatFloat/Slowpath64-8 47.74n ± 2% 45.85n ± 0% -3.96% (p=0.000 n=10)
FormatFloat/SlowpathDenormal64-8 42.78n ± 1% 41.46n ± 0% -3.07% (p=0.000 n=10)
FormatFloat/ShorterIntervalCase32-8 25.49n ± 2%
FormatFloat/ShorterIntervalCase64-8 27.72n ± 1%
geomean 41.95n 31.89n -22.11%
Fixes #74886