* [ruby-core:121829] [Ruby Feature#21308] Replacing the Float#to_s (dtoa.c) implementation with a modern algorithm
@ 2025-05-05 9:40 watson1978 (Shizuo Fujita) via ruby-core
2025-05-06 9:20 ` [ruby-core:121844] " nobu (Nobuyoshi Nakada) via ruby-core
2025-05-13 7:57 ` [ruby-core:122041] " radiospiel (Enrico Thierbach) via ruby-core
0 siblings, 2 replies; 3+ messages in thread
From: watson1978 (Shizuo Fujita) via ruby-core @ 2025-05-05 9:40 UTC (permalink / raw)
To: ruby-core; +Cc: watson1978 (Shizuo Fujita)
Issue #21308 has been reported by watson1978 (Shizuo Fujita).
----------------------------------------
Feature #21308: Replacing the Float#to_s (dtoa.c) implementation with a modern algorithm
https://bugs.ruby-lang.org/issues/21308
* Author: watson1978 (Shizuo Fujita)
* Status: Open
----------------------------------------
This is a feature request to replace Ruby's `Float#to_s` implementation with a modern high-performance float-to-string conversion algorithm such as Grisu.
Currently, `Float#to_s` in Ruby uses the BSD-derived implementation in [missing/dtoa.c](https://github.com/ruby/ruby/blob/master/missing/dtoa.c).
Meanwhile, `json` gem has adopted a Grisu-based implementation in [ruby/json#768](https://github.com/ruby/json/pull/768), it has been improve the performance of float-to-string conversion dramatically.
It appears to have brought about a 10 times improvement in performance.
However, the improvement is limited to the `json` gem.
If we can use the same implementation in `Float#to_s`, it will introduce the improvement in all float-to-string conversion cases.
(In additional, it would be better if an API could be added that could be called directly from the C extension library, it will reduce the overhead of the call.)
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:121844] [Ruby Feature#21308] Replacing the Float#to_s (dtoa.c) implementation with a modern algorithm
2025-05-05 9:40 [ruby-core:121829] [Ruby Feature#21308] Replacing the Float#to_s (dtoa.c) implementation with a modern algorithm watson1978 (Shizuo Fujita) via ruby-core
@ 2025-05-06 9:20 ` nobu (Nobuyoshi Nakada) via ruby-core
2025-05-13 7:57 ` [ruby-core:122041] " radiospiel (Enrico Thierbach) via ruby-core
1 sibling, 0 replies; 3+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2025-05-06 9:20 UTC (permalink / raw)
To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)
Issue #21308 has been updated by nobu (Nobuyoshi Nakada).
The interface of `fpconv_dtoa()` looks quite different from `dtoa()` in missing/dtoa.c.
Rather `grisu2()` itself is closer?
----------------------------------------
Feature #21308: Replacing the Float#to_s (dtoa.c) implementation with a modern algorithm
https://bugs.ruby-lang.org/issues/21308#change-112906
* Author: watson1978 (Shizuo Fujita)
* Status: Open
----------------------------------------
This is a feature request to replace Ruby's `Float#to_s` implementation with a modern high-performance float-to-string conversion algorithm such as Grisu.
Currently, `Float#to_s` in Ruby uses the BSD-derived implementation in [missing/dtoa.c](https://github.com/ruby/ruby/blob/master/missing/dtoa.c).
Meanwhile, `json` gem has adopted a Grisu-based implementation in [ruby/json#768](https://github.com/ruby/json/pull/768), it has been improve the performance of float-to-string conversion dramatically.
It appears to have brought about a 10 times improvement in performance.
However, the improvement is limited to the `json` gem.
If we can use the same implementation in `Float#to_s`, it will introduce the improvement in all float-to-string conversion cases.
(In additional, it would be better if an API could be added that could be called directly from the C extension library, it will reduce the overhead of the call.)
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:122041] [Ruby Feature#21308] Replacing the Float#to_s (dtoa.c) implementation with a modern algorithm
2025-05-05 9:40 [ruby-core:121829] [Ruby Feature#21308] Replacing the Float#to_s (dtoa.c) implementation with a modern algorithm watson1978 (Shizuo Fujita) via ruby-core
2025-05-06 9:20 ` [ruby-core:121844] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2025-05-13 7:57 ` radiospiel (Enrico Thierbach) via ruby-core
1 sibling, 0 replies; 3+ messages in thread
From: radiospiel (Enrico Thierbach) via ruby-core @ 2025-05-13 7:57 UTC (permalink / raw)
To: ruby-core; +Cc: radiospiel (Enrico Thierbach)
Issue #21308 has been updated by radiospiel (Enrico Thierbach).
The change in https://github.com/ruby/json/pull/768 was an easy win, because the previous implementation was calling into question`Float#to_s` via `rb_funcall`. The overhead of doing so is so extreme, that any implementation that would skirt that would show a massive improvement already.
In fact, a first attempt using dtoa.c already showed a 600% or so performance improvement on a clinical example.
I then decided that maybe this would also be a great moment to look at alternative implementations, since the flexibility provided by dtoa.c is not necessary in the context of the json gem. Other motivational factors have been:
- dtoa generates output right to left (IIRC), but, at least for an integration with the json gem, generating left to right saves a memcpy, which would add a 5-10% overhead;
- more modern algorithms are readily available.
I believe integrating a more modern implementation in the ruby runtime certainly is benefitial, but the gains are not as massive as @watson1978 hopes to achieve here, unfortunately.
----------------------------------------
Feature #21308: Replacing the Float#to_s (dtoa.c) implementation with a modern algorithm
https://bugs.ruby-lang.org/issues/21308#change-113190
* Author: watson1978 (Shizuo Fujita)
* Status: Open
----------------------------------------
This is a feature request to replace Ruby's `Float#to_s` implementation with a modern high-performance float-to-string conversion algorithm such as Grisu.
Currently, `Float#to_s` in Ruby uses the BSD-derived implementation in [missing/dtoa.c](https://github.com/ruby/ruby/blob/master/missing/dtoa.c).
Meanwhile, `json` gem has adopted a Grisu-based implementation in [ruby/json#768](https://github.com/ruby/json/pull/768), it has been improve the performance of float-to-string conversion dramatically.
It appears to have brought about a 10 times improvement in performance.
However, the improvement is limited to the `json` gem.
If we can use the same implementation in `Float#to_s`, it will introduce the improvement in all float-to-string conversion cases.
(In additional, it would be better if an API could be added that could be called directly from the C extension library, it will reduce the overhead of the call.)
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-13 7:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-05 9:40 [ruby-core:121829] [Ruby Feature#21308] Replacing the Float#to_s (dtoa.c) implementation with a modern algorithm watson1978 (Shizuo Fujita) via ruby-core
2025-05-06 9:20 ` [ruby-core:121844] " nobu (Nobuyoshi Nakada) via ruby-core
2025-05-13 7:57 ` [ruby-core:122041] " radiospiel (Enrico Thierbach) via ruby-core
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).