21 Commits
Author SHA1 Message Date
Jean Boussier 0384a27828 [ruby/json] fast_float_parser.h: fix GCC 8 support
https://github.com/ruby/json/commit/cdad7dfb26
2026-06-16 13:44:04 +00:00
Jean Boussier 99d5f19eef [ruby/json] fast_float_parser.h: handle __has_builtin not being defined
https://github.com/ruby/json/commit/97dda65096
2026-06-16 13:00:29 +00:00
Jean Boussier c8ec3b96d5 [ruby/json] fast_float_parser.h: copy nlz_int64 from the bigdecimal gem
https://github.com/ruby/json/commit/2203b8dce2
2026-06-16 12:25:07 +00:00
Jean Boussier 48dabba2d9 [ruby/json] fast_float_parser.h: handle more environments
Inspired by bigdecimal

https://github.com/ruby/json/commit/8d2a1ff57d
2026-06-16 11:01:51 +00:00
Jean Boussier 3b582d1b62 [ruby/json] fast_float_parser.h: handle __has_builtin not being defined
https://github.com/ruby/json/commit/34bc289d69
2026-06-16 10:10:51 +00:00
Jean Boussier 1096a7b57f [ruby/json] fast_float_parser.h: add portable __builtin_clzll
Required for Windows support.

https://github.com/ruby/json/commit/c171e34939
2026-06-16 07:42:35 +00:00
Jean Boussier 61e2d8e36f [ruby/json] Replace Ryu with a C99 port of fast_float
Contrary to Ryu, it remains correct up to 18 mantissa digits,
meaning we don't have to fallback as much to Ruby's much slower
`rb_cstr_to_dbl`.

On `canada.json`, the most number heavy benchmark, `ffp_s2d` is less
than 5% of total runtime. Most of the time is actually sent parsing,
not decoding.

There is a more complete C99 port of `fast_float` at
https://github.com/kolemannix/ffc.h which also does parsing and
could be worth considering, however it might make it much harder
to detect when we're outside the safe range and to fallback,
so unclear if it would be a win.

Credit to Tilo Sloboda for the C99 port (sligthly reworked).

```
== Parsing citm_catalog.json (500124 bytes)
ruby 4.0.5 (2026-05-20 revision https://github.com/ruby/json/commit/64336ffd0e) +YJIT +PRISM [arm64-darwin25]
Warming up --------------------------------------
               after    73.000 i/100ms
Calculating -------------------------------------
               after    733.301 (± 1.0%) i/s    (1.36 ms/i) -      3.723k in   5.077044s

Comparison:
before:      716.8 i/s
 after:      733.3 i/s - 1.02x  faster

== Parsing float parsing (2090303 bytes)
ruby 4.0.5 (2026-05-20 revision https://github.com/ruby/json/commit/64336ffd0e) +YJIT +PRISM [arm64-darwin25]
Warming up --------------------------------------
               after    35.000 i/100ms
Calculating -------------------------------------
               after    353.130 (± 0.3%) i/s    (2.83 ms/i) -      1.785k in   5.054791s

Comparison:
before:      323.1 i/s
 after:      353.1 i/s - 1.09x  faster
```

https://github.com/ruby/json/commit/4185ef1a7b
2026-06-16 07:42:35 +00:00
久我山菜々 8ccfb375b9 [ruby/json] Update fpconv_dtoa definition to use dest[32]
https://github.com/ruby/json/commit/4808fee9af
2025-12-26 11:00:51 +09:00
Scott Myron f272aabb5c [ruby/json] Use #if instead of #ifdef when checking for JSON_DEBUG so debugging code is not generated when JSON_DEBUG=0.
https://github.com/ruby/json/commit/4f1adb10d3
2025-11-18 08:20:51 +00:00
Josef ŠimánekandJean Boussier 3ca4321680 [ruby/json] Add ryu float parser.
https://github.com/ruby/json/commit/9c4db31908

Co-Authored-By: Jean Boussier <jean.boussier@gmail.com>
2025-10-30 10:56:36 +00:00
Jean Boussier dc406e9b5b [ruby/json] Avoid scientific notation before exponent 15
Fix: https://github.com/ruby/json/issues/861

It's not incorrect to use scientific notation, but it tend
to throw people off a bit, so it's best to keep it for very large
numbers.

https://github.com/ruby/json/commit/1566cd01a6
2025-09-19 19:30:10 +09:00
Jean Boussier f171a263f7 [ruby/json] Fix: generate_json_float to reserve enough memory for large negative floats.
Fix: https://github.com/ruby/json/issues/807

Since https://github.com/ruby/json/pull/800, `fpconv_dtoa` can actually
generate up to 28 chars.

https://github.com/ruby/json/commit/d73ae93d3c
2025-05-26 11:46:12 +09:00
Nobuyoshi Nakada d2ffdb1088 Explicit cast down from double to int 2025-05-12 17:45:39 +09:00
Jean Boussier af79914002 [ruby/json] Favor decimal notation over scientific notation for floats
e.g.
```
JSON.dump(1746861937.7842371)
```

master:
```
"1.https://github.com/ruby/json/commit/746861937784+9"
```

This branch and older json versions:
```
https://github.com/ruby/json/commit/1746861937.7842371
```

In the end it's shorter, and according to `canada.json` benchmark
performance is the same.

https://github.com/ruby/json/commit/866f72a437
2025-05-12 11:09:11 +09:00
Nobuyoshi Nakada 61b6f226e8 [ruby/json] Constify static data in fpconv.c
https://github.com/ruby/json/commit/3b605d9b1e
2025-05-08 18:03:04 +09:00
Jean Boussier ae45a7a952 [ruby/json] Cleanup jeaiii-ltoa to not need pragmas
https://github.com/ruby/json/commit/97f2924d0a
2025-04-09 08:11:03 +09:00
Nobuyoshi Nakada b1362e26c7 [ruby/json] Suppress -Wunknown-pragmas warnings
https://github.com/ruby/json/commit/97f47d1cfd
2025-04-09 08:11:03 +09:00
Jean Boussier 4dde7101c7 Refactor jeaiii-ltoa.h
Some relatively minor change to make the library more in line
with the gem. Some renaming, etc.
2025-03-27 13:54:12 +09:00
Hiroshi SHIBATA ee85745c61 Removed trailing spaces 2025-03-27 11:37:27 +09:00
eno d1f3c81258 Faster integer formatting
This commit provides an alternative implementation for a
long → decimal conversion.

The main difference is that it uses an algorithm pulled from
https://github.com/jeaiii/itoa.
The source there is C++, it was converted by hand to C for
inclusion with this gem.
jeaiii's algorithm is covered by the MIT License, see source code.

On addition this version now also generates the string directly into
the fbuffer, foregoing the need to run a separate memory copy.

As a result, I see a speedup of 32% on Apple Silicon M1 for an
integer set of benchmarks.
2025-03-27 11:37:27 +09:00
Jean Boussier f3f4524d19 Reorganize fpconv vendoring
Make it a single file and declare the dependency.
2025-03-24 14:49:44 +09:00