Skip to content

Ryu Implementation for Float-to-string Conversion#1078

Closed
zihaowang678 wants to merge 2 commits into
amazon-ion:masterfrom
zihaowang678:ryu
Closed

Ryu Implementation for Float-to-string Conversion#1078
zihaowang678 wants to merge 2 commits into
amazon-ion:masterfrom
zihaowang678:ryu

Conversation

@zihaowang678

@zihaowang678 zihaowang678 commented Jun 27, 2025

Copy link
Copy Markdown
Contributor

Overview

This PR adds an implementation of the Ryu algorithm for efficient and accurate float-to-string conversion in ion-java. The Ryu algorithm provides performance improvements over traditional approaches while maintaining correctness.

Changes

  • Added RyuDouble.java which implements the core Ryu algorithm for double values
  • Added RoundingMode.java to support different rounding strategies
  • Integrated with the existing Ion Java codebase for floating-point serialization

Benefits

  • Performance comparable to or faster than the native Double.toString() method in JDK 21
  • Consistent serialized size with runtime JDK 21; reduced serialized size with runtime JDK 17 and lower versions
  • Improved memory allocation efficiency for JDK 17 and lower versions
  • Guaranteed shortest correctly rounded string representation

References

  • Original Ryu paper: "Ryū: fast float-to-string conversion" by Ulf Adams
  • Implementation based on the reference Java version with adaptations for Ion's requirements

License

The implementation maintains the original Apache 2.0 license from Ulf Adams' reference implementation.

@codecov

codecov Bot commented Jun 27, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 55.96026% with 133 lines in your changes missing coverage. Please review.

Project coverage is 67.71%. Comparing base (3c1b6b1) to head (88cdaac).
Report is 112 commits behind head on master.

Files with missing lines Patch % Lines
...c/main/java/com/amazon/ion/impl/ryu/RyuDouble.java 56.12% 99 Missing and 30 partials ⚠️
...ain/java/com/amazon/ion/impl/ryu/RoundingMode.java 42.85% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1078      +/-   ##
============================================
+ Coverage     67.23%   67.71%   +0.48%     
- Complexity     5484     5603     +119     
============================================
  Files           159      162       +3     
  Lines         23025    23387     +362     
  Branches       4126     4218      +92     
============================================
+ Hits          15481    15837     +356     
+ Misses         6262     6247      -15     
- Partials       1282     1303      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tgregg tgregg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's something to try.

Since we'd be copying in the code with attribution instead of taking a dependency, we can modify the algorithm slightly to fit our needs.

You could try modifying the algorithm to output text Ion floats natively without the post-processing steps here: https://github.com/amazon-ion/ion-java/pull/1078/files#diff-b3377504685a7b6e1dddbc955be3d9c24e4f2e57e2e26a705c2733d2e5d88dabR844-R856

Maybe that would enable additional performance benefits.

@zihaowang678 zihaowang678 marked this pull request as ready for review July 11, 2025 21:54
@zihaowang678

Copy link
Copy Markdown
Contributor Author

Implement Schubfach instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants