Граф коммитов

9394 Коммитов

Автор SHA1 Сообщение Дата
Misaki Shioi d21b614bd4
[DOC] Improve `Socket::tcp` with Happy Eyeballs Version 2
With the introduction of Happy Eyeballs Version 2 to `Socket::tcp`, the following areas have been mainly enhanced:

- How the value specified for `connect_timeout` works
- How Socket.tcp operates with Happy Eyeballs Version 2

A description for the new option `fast_fallback` has been added in https://github.com/ruby/ruby/pull/11813.
2024-10-20 19:26:01 +09:00
Takumasa Ochi 20dc1e5c25 [ruby/json] Always dup argument to preserve original encoding for force_encoding
https://github.com/ruby/json/commit/db9a489ca2
2024-10-18 11:30:42 +09:00
YuheiNakasaka 57e1b64c81 [ruby/json] Fix behavior of trying to parse non-string objects
https://github.com/ruby/json/commit/e2e9936047
2024-10-18 11:28:13 +09:00
Jean Boussier c4d4c6b846 [ruby/json] Speedup Parser initialization
Extracted from: https://github.com/ruby/json/pull/512

Use `rb_hash_lookup2` to check for hash key existence instead
of going through `rb_funcall`.

https://github.com/ruby/json/commit/43835a0d13

Co-Authored-By: lukeg <luke.gru@gmail.com>
2024-10-18 11:28:12 +09:00
Peter Zhu 48899d56a9 [ruby/json] Sync changes
Some changes were missed in the automatic sync.
2024-10-17 21:07:54 +02:00
Peter Zhu e4330536d2 [ruby/json] Fix State#max_nesting=
Returning state->max_nesting is not valid because it's not a Ruby object.

https://github.com/ruby/json/commit/6679ceb
2024-10-17 13:39:48 -04:00
Jean Boussier a7317f53e0 Add a fast path for ASCII strings
This optimization is based on a few assumptions:

  - Most strings are ASCII only.
  - Most strings had their coderange scanned already.

If the above is true, then by checking the string coderange, we can
use a much more streamlined function to encode ASCII strings.

Before:

```
== Encoding twitter.json (466906 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
                json   140.000 i/100ms
                  oj   230.000 i/100ms
           rapidjson   108.000 i/100ms
Calculating -------------------------------------
                json      1.464k (± 1.4%) i/s  (682.83 μs/i) -      7.420k in   5.067573s
                  oj      2.338k (± 1.5%) i/s  (427.64 μs/i) -     11.730k in   5.017336s
           rapidjson      1.075k (± 1.6%) i/s  (930.40 μs/i) -      5.400k in   5.025469s

Comparison:
                json:     1464.5 i/s
                  oj:     2338.4 i/s - 1.60x  faster
           rapidjson:     1074.8 i/s - 1.36x  slower

```

After:

```
== Encoding twitter.json (466906 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
                json   189.000 i/100ms
                  oj   228.000 i/100ms
           rapidjson   108.000 i/100ms
Calculating -------------------------------------
                json      1.903k (± 1.2%) i/s  (525.55 μs/i) -      9.639k in   5.066521s
                  oj      2.306k (± 1.3%) i/s  (433.71 μs/i) -     11.628k in   5.044096s
           rapidjson      1.069k (± 2.4%) i/s  (935.38 μs/i) -      5.400k in   5.053794s

Comparison:
                json:     1902.8 i/s
                  oj:     2305.7 i/s - 1.21x  faster
           rapidjson:     1069.1 i/s - 1.78x  slower
```
2024-10-17 15:21:34 +00:00
Jean Boussier df48f597cf [ruby/json] Get rid of some more outdated compatibility code
All these macros are available on Ruby 2.3+

https://github.com/ruby/json/commit/227885f460
2024-10-17 13:02:13 +00:00
Jean Boussier 6105bae331 [ruby/json] Get rid of compatibility code for older rubies
All of these are for rubies older than 2.3.

https://github.com/ruby/json/commit/811297f86a
2024-10-17 12:22:16 +00:00
Jean Boussier 0e2ac46584 Optimize Ext::Generator::State#configure
If we assume that most of the time the `opts` hash is small
it's faster to go over the provided keys with a `case` than
to test all possible keys one by one.

Before:

```
== Encoding small nested array (121 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
                json   156.832k i/100ms
                  oj   209.769k i/100ms
           rapidjson   162.922k i/100ms
Calculating -------------------------------------
                json      1.599M (± 2.5%) i/s  (625.34 ns/i) -      7.998M in   5.005110s
                  oj      2.137M (± 1.5%) i/s  (467.99 ns/i) -     10.698M in   5.007806s
           rapidjson      1.677M (± 3.5%) i/s  (596.31 ns/i) -      8.472M in   5.059515s

Comparison:
                json:  1599141.2 i/s
                  oj:  2136785.3 i/s - 1.34x  faster
           rapidjson:  1676977.2 i/s - same-ish: difference falls within error

== Encoding small hash (65 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
                json   216.464k i/100ms
                  oj   661.328k i/100ms
           rapidjson   324.434k i/100ms
Calculating -------------------------------------
                json      2.301M (± 1.7%) i/s  (434.57 ns/i) -     11.689M in   5.081278s
                  oj      7.244M (± 1.2%) i/s  (138.05 ns/i) -     36.373M in   5.021985s
           rapidjson      3.323M (± 2.9%) i/s  (300.96 ns/i) -     16.871M in   5.081696s

Comparison:
                json:  2301142.2 i/s
                  oj:  7243770.3 i/s - 3.15x  faster
           rapidjson:  3322673.0 i/s - 1.44x  faster
```

After:

```
== Encoding small nested array (121 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
                json   168.087k i/100ms
                  oj   208.872k i/100ms
           rapidjson   149.909k i/100ms
Calculating -------------------------------------
                json      1.761M (± 1.1%) i/s  (567.90 ns/i) -      8.909M in   5.059794s
                  oj      2.144M (± 0.9%) i/s  (466.37 ns/i) -     10.861M in   5.065903s
           rapidjson      1.692M (± 1.7%) i/s  (591.04 ns/i) -      8.545M in   5.051808s

Comparison:
                json:  1760868.2 i/s
                  oj:  2144205.9 i/s - 1.22x  faster
           rapidjson:  1691941.1 i/s - 1.04x  slower

== Encoding small hash (65 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
                json   242.957k i/100ms
                  oj   675.217k i/100ms
           rapidjson   355.040k i/100ms
Calculating -------------------------------------
                json      2.569M (± 1.5%) i/s  (389.22 ns/i) -     12.877M in   5.013095s
                  oj      7.128M (± 2.3%) i/s  (140.30 ns/i) -     35.787M in   5.023594s
           rapidjson      3.656M (± 3.1%) i/s  (273.50 ns/i) -     18.462M in   5.054558s

Comparison:
                json:  2569217.5 i/s
                  oj:  7127705.6 i/s - 2.77x  faster
           rapidjson:  3656285.0 i/s - 1.42x  faster
```
2024-10-17 11:35:33 +00:00
Jean Boussier a1c420c740 [ruby/json] generator.c: reduce the number of globals
Most of these classes and modules don't need to be global variables

https://github.com/ruby/json/commit/b783445ec9
2024-10-17 11:35:32 +00:00
Jean Boussier 43e08133c3 [ruby/json] Convert Generator initialize and configure method into Ruby
This helps very marginally with allocation speed.

https://github.com/ruby/json/commit/25db79dfaa
2024-10-17 11:35:32 +00:00
Jean Boussier 494d814637 Optimize JSON.dump argument parsing
`JSON.dump` looks terrible on micro-benchmarks because the way it
handles arguments is quite allocation heavy compared to the actual
JSON generation work.

Profiling the `small hash` benchmarked show 14% of time spent in `Array#compact`
and `34%` time spent in `JSON::Ext::GeneratorState.new`. Only `41%` in the
actual `generate` function.

By micro-optimizing `JSON.dump`, it can look much better:

Before:

```
== Encoding small nested array (121 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
                json    91.687k i/100ms
                  oj   205.309k i/100ms
           rapidjson   161.648k i/100ms
Calculating -------------------------------------
                json    941.965k (± 1.4%) i/s    (1.06 μs/i) -      4.768M in   5.062573s
                  oj      2.138M (± 1.2%) i/s  (467.82 ns/i) -     10.881M in   5.091254s
           rapidjson      1.678M (± 1.9%) i/s  (596.04 ns/i) -      8.406M in   5.011931s

Comparison:
                json:   941964.8 i/s
                  oj:  2137586.5 i/s - 2.27x  faster
           rapidjson:  1677737.1 i/s - 1.78x  faster

== Encoding small hash (65 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
                json   141.737k i/100ms
                  oj   676.871k i/100ms
           rapidjson   373.266k i/100ms
Calculating -------------------------------------
                json      1.491M (± 1.0%) i/s  (670.78 ns/i) -      7.512M in   5.039463s
                  oj      7.226M (± 1.4%) i/s  (138.39 ns/i) -     36.551M in   5.059475s
           rapidjson      3.729M (± 2.2%) i/s  (268.15 ns/i) -     18.663M in   5.007182s

Comparison:
                json:  1490798.2 i/s
                  oj:  7225766.2 i/s - 4.85x  faster
           rapidjson:  3729192.2 i/s - 2.50x  faster
```

After:

```
== Encoding small nested array (121 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
                json   156.832k i/100ms
                  oj   209.769k i/100ms
           rapidjson   162.922k i/100ms
Calculating -------------------------------------
                json      1.599M (± 2.5%) i/s  (625.34 ns/i) -      7.998M in   5.005110s
                  oj      2.137M (± 1.5%) i/s  (467.99 ns/i) -     10.698M in   5.007806s
           rapidjson      1.677M (± 3.5%) i/s  (596.31 ns/i) -      8.472M in   5.059515s

Comparison:
                json:  1599141.2 i/s
                  oj:  2136785.3 i/s - 1.34x  faster
           rapidjson:  1676977.2 i/s - same-ish: difference falls within error

== Encoding small hash (65 bytes)
ruby 3.4.0preview2 (2024-10-07 master 32c733f57b) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
                json   216.464k i/100ms
                  oj   661.328k i/100ms
           rapidjson   324.434k i/100ms
Calculating -------------------------------------
                json      2.301M (± 1.7%) i/s  (434.57 ns/i) -     11.689M in   5.081278s
                  oj      7.244M (± 1.2%) i/s  (138.05 ns/i) -     36.373M in   5.021985s
           rapidjson      3.323M (± 2.9%) i/s  (300.96 ns/i) -     16.871M in   5.081696s

Comparison:
                json:  2301142.2 i/s
                  oj:  7243770.3 i/s - 3.15x  faster
           rapidjson:  3322673.0 i/s - 1.44x  faster
```

Now profiles of the `small hash` benchmark show 44% in `generate` and
`45%` in `GeneratorState` allocation.
2024-10-17 09:31:32 +00:00
Yusuke Endoh 233f63c7fb [ruby/json] Use `RB_ENCODING_GET` instead of `rb_enc_get` to improve performance
This speeds up `JSON.generate` by about 12% in a benchmark.

https://github.com/ruby/json/commit/4329e30826
2024-10-17 08:54:48 +00:00
Yusuke Endoh 0b4257efa3 [ruby/json] Apply RB_UNLIKELY for less frequently used options
This speeds up `JSON.generate` by about 4% in a benchmark.

https://github.com/ruby/json/commit/6471710cfc
2024-10-17 08:54:47 +00:00
Yusuke Endoh 64c24f6971 [ruby/json] Stop prebuilding object_delim2
Also, remove static functions that are no longer used.

This speeds up `JSON.generate` by about 5% in a benchmark.

https://github.com/ruby/json/commit/4c984b2017
2024-10-17 08:54:47 +00:00
Yusuke Endoh 186e77209e [ruby/json] Stop prebuilding object_delim
This speeds up `JSON.generate` by about 4% in a benchmark

https://github.com/ruby/json/commit/ed47a10e4f
2024-10-17 08:54:47 +00:00
Yusuke Endoh 88719fb300 [ruby/json] Stop prebuilding array_delim
The purpose of this change is to exploit `fbuffer_append_char` that is
faster than `fbuffer_append`.

`array_delim` was a buffer that concatenated a single comma with
`array_nl`. However, in the typical use case (`JSON.generate(data)`),
`array_nl` is empty. This means that `array_delim` was a
single-character buffer in many cases.

`fbuffer_append(buffer, array_delim)` used `memcpy` to copy one byte,
which was not so efficient.
Rather, this change uses `fbuffer_append_char(buffer, ',')` and then
`fbuffer_append(buffer, array_nl)` only when `array_nl` is not NULL.

This speeds up `JSON.generate` by about 9% in a benchmark.

https://github.com/ruby/json/commit/445de6e459
2024-10-17 08:54:46 +00:00
Yusuke Endoh fb84aa5501 [ruby/json] Directly use `generate_json_string` for object keys
... instead of `generate_json`.

Since the object key is already confirmed to be a string, using a
generic dispatch function brings an unnecessary overhead.

This speeds up `JSON.generate` by about 3% in a benchmark.

https://github.com/ruby/json/commit/e125072130
2024-10-17 08:54:46 +00:00
Yusuke Endoh 3911189fba [ruby/json] Use efficient object-type dispatching
Dispatching based on Ruby's VALUE structure is more efficient than
simply cascaded "if ... else if ..." checks.

This speeds up `JSON.generate` by about 5% in a benchmark.

https://github.com/ruby/json/commit/4f9180debb
2024-10-17 08:54:45 +00:00
Yusuke Endoh 7962b4c342 [ruby/json] Use `RARRAY_AREF` instead of `rb_ary_entry` to improve performance
It is safe to use `RARRAY_AREF` here because no Ruby code is executed
between `RARRAY_LEN` and `RARRAY_AREF`.

This speeds up `JSON.generate` by about 4% in a benchmark.

https://github.com/ruby/json/commit/c5d80f9fd4
2024-10-17 08:54:45 +00:00
Nobuyoshi Nakada 9da60a14bf [ruby/etc] Fix sysconfdir when load-relative
When relative load paths option is enabled, the prefix is determined
at the runtime.  The only way to get it outside libruby is to use
rbconfig.rb.

https://github.com/ruby/etc/commit/e5b498fad9
2024-10-17 07:32:38 +00:00
Nobuyoshi Nakada 72b8fa9e03 [ruby/win32-registry] Exclude rake files from packages [ci skip]
https://github.com/ruby/win32-registry/commit/e7b2eeb885
2024-10-17 03:09:32 +00:00
Nobuyoshi Nakada 34d800ebcd [ruby/win32-registry] Exclude mailmap from packages [ci skip]
https://github.com/ruby/win32-registry/commit/521f93af9e
2024-10-17 02:12:18 +00:00
Lars Kanis 85ce3b177c [ruby/win32-registry] Fix compatibility with JRuby
JRuby's fiddle implementation has quite some shortcomings compared with the CRuby impl.
Add JRuby tests in CI.

https://github.com/ruby/win32-registry/commit/7f34184c2e
2024-10-17 01:51:41 +00:00
Sutou Kouhei 80136b6abc
Bump version 2024-10-16 11:24:25 +09:00
Sutou Kouhei 8d127c9b59
Use JRuby implementation for TruffleRuby (#149)
Fix GH-145

Rename `lib/fiddle/jruby.rb` to `lib/fiddle/ffi_backend.rb` as a generic
ffi gem API based implementation.
JRuby and TruffleRuby use `lib/fiddle/ffi_backend.rb`.

---------

Co-authored-by: Benoit Daloze <eregontp@gmail.com>
2024-10-16 11:24:25 +09:00
Nobuyoshi Nakada bbd5b8ddae
[ruby/fiddle] Ractor support
(https://github.com/ruby/fiddle/pull/139)

https://github.com/ruby/fiddle/commit/91d0ea9849

Co-authored-by: Sutou Kouhei <kou@clear-code.com>
2024-10-16 11:24:25 +09:00
Hiroshi SHIBATA 48f953d6ba [ruby/json] Added license files on gemspec
https://github.com/ruby/json/commit/81092639e8
2024-10-15 11:48:32 +00:00
Jean Boussier 7eed1df1ab [ruby/json] Update gemspec files
https://github.com/ruby/json/commit/0f9564104f
2024-10-15 11:35:47 +00:00
John Bampton afacb8ada5
[DOC] Fix spelling 2024-10-12 12:48:10 +00:00
Samuel Williams ad5641fd34
Support `IO#timeout` for `rsock_connect`. (#11880) 2024-10-12 10:08:34 +13:00
Nobuyoshi Nakada 2c3d26cfd7
Fix an implicit conversion that loses integer precision
Both `rb_ensure` and `udp_bind_internal` return `VALUE`.
2024-10-11 16:37:51 +09:00
Samuel Williams c43be94f76
Update `rsock_connect` to take `VALUE io` argument. (#11847) 2024-10-11 18:36:11 +13:00
Nobuyoshi Nakada cd611becbb
[ruby/fiddle] Cast via `VALUE` function pointer between object
pointer
(https://github.com/ruby/fiddle/pull/150)

With gcc 13 and -pedantic:

```
../../../src/ext/fiddle/function.c: In function ‘function_call’:
../../../src/ext/fiddle/function.c:374:15: error: ISO C forbids conversion of object pointer to function pointer type [-Wpedantic]
  374 |     args.fn = (void(*)(void))NUM2PTR(cfunc);
      |               ^
../../../src/ext/fiddle/pointer.c: In function ‘rb_fiddle_ptr_inspect’:
../../../src/ext/fiddle/pointer.c:573:84: error: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
  573 |                       RB_OBJ_CLASSNAME(self), (void *)data, data->ptr, data->size, (void *)data->free);
      |                                                                                    ^
```

https://github.com/ruby/fiddle/commit/6421e317a1
2024-10-10 23:52:07 +09:00
Nobuyoshi Nakada 146ff66173 [ruby/digest] Cast via `uintptr_t` function pointer between object pointer
https://github.com/ruby/digest/commit/661d4643ef
2024-10-10 14:45:49 +00:00
Nobuyoshi Nakada 51fdd2c6ca
Move directives outside `rb_ary_new3` call
This function may be a macro for optimization, which will be expanded
to `rb_ary_new_from_values`.

```
ext/socket/ancdata.c: In function ‘bsock_recvmsg_internal’:
ext/socket/ancdata.c:1648:1: error: embedding a directive within macro arguments is not portable
 1648 | #if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
      | ^
ext/socket/ancdata.c:1650:1: error: embedding a directive within macro arguments is not portable
 1650 | #else
      | ^
ext/socket/ancdata.c:1652:1: error: embedding a directive within macro arguments is not portable
 1652 | #endif
      | ^
```
2024-10-10 11:30:37 +09:00
Nobuyoshi Nakada 6f6735898a
Cast via `uintptr_t` function pointer between object pointer 2024-10-10 11:29:57 +09:00
Sutou Kouhei a47f153d9d
Import JRuby implementation (#147)
Fix GH-104

lib/fiddle/jruby.rb is based on

https://github.com/jruby/jruby/blob/master/lib/ruby/stdlib/fiddle/jruby.rb
.

Here are changes for it:

* Move `Fiddle::TYPE_*` to `Fiddle::Types::*`
* Add `Fiddle::Types::VARIADIC`
* Add `Fiddle::Types::CONST_STRING`
* Add `Fiddle::Types::BOOL`
* Add `Fiddle::Types::INT8_T`
* Add `Fiddle::Types::UINT8_T`
* Add `Fiddle::Types::INT16_T`
* Add `Fiddle::Types::UINT16_T`
* Add `Fiddle::Types::INT32_T`
* Add `Fiddle::Types::UINT32_T`
* Add `Fiddle::Types::INT64_T`
* Add `Fiddle::Types::UINT64_T`
* Add more `Fiddle::ALIGN_*` for the above new `Fiddle::Types::*`
* Add more `Fiddle::SIZEOF_*` for the above new `Fiddle::Types::*`
* Add support for specifying type as not only `Fiddle::Types::*` but
also `Symbol` like `:int`
* Add support for variable size arguments in `Fiddle::Function`
* Add `Fiddle::Closure#free`
* Add `Fiddle::Closure#freed?`
* Add `Fiddle::Error` as base the error class
* Add `Fiddle::Pointer#call_free` and stop using `FFI::AutoPointer` in
`Fiddle::Pointer`
* Add support for `Fiddle::Pointer.malloc {}` `Fiddle::Pointer`
* Add support for `Fiddle::Pointer#free=`
* Add `Fiddle::Pointer#freed?`
* Use binary string not C string for `Fiddle::Pointer#[]`
* Add `Fiddle::Handle.sym_defined?`
* Add `Fiddle::Handle#sym_defined?`
* Add `Fiddle::Handle::DEFAULT`
* Add `Fiddle::ClearedReferenceError`
* Add no-op `Fiddle::Pinned`

Some features are still "not implemented". So there are some "omit"s for
JRuby in tests.
2024-10-10 10:05:52 +09:00
Samuel Williams 438ef21a9b Update `Socket#recvfrom` to use `rb_io_blocking_region`. 2024-10-09 23:48:53 +13:00
Samuel Williams 04ddb7e808 Update `Socket#accept` to use `rb_io_blocking_region`. 2024-10-09 23:48:53 +13:00
Samuel Williams 3031bf6bd4 Update `UDPSocket#send` to use `rb_io_blocking_region`. 2024-10-09 23:48:53 +13:00
Samuel Williams 823f29a36e Update `IPSocket` to use `rb_io_descriptor` and `rb_io_mode`. 2024-10-09 21:05:01 +13:00
Samuel Williams d78bf43708 Update `UNIXSocket` to use `rb_io_blocking_region`. 2024-10-09 21:05:01 +13:00
Samuel Williams dee15211c1 Update `BasicSocket` to use `rb_io_blocking_region`. 2024-10-09 21:05:01 +13:00
Hiroshi SHIBATA 4eda289a13 Sync from ruby/win32-registry 2024-10-09 13:55:45 +09:00
Nobuyoshi Nakada 9a90cd2284 Cast via `uintptr_t` function pointer between object pointer
- ISO C forbids conversion of function pointer to object pointer type
- ISO C forbids conversion of object pointer to function pointer type
2024-10-08 23:29:49 +09:00
Jean Boussier 613694734e [ruby/json] generator.c: better fix for comparison of integers of different signs
https://github.com/ruby/json/commit/c372dc9268
2024-10-08 12:22:42 +00:00
Hiroshi SHIBATA 02d4703eed Extract ext/win32/lib/win32/sspi.rb to ruby/win32-sspi 2024-10-08 17:11:44 +09:00
Hiroshi SHIBATA c684164534 Fixed C23 compilation error with ruby/ruby master 2024-10-08 14:10:05 +09:00