[#119000] [Ruby master Bug#20710] Reducing Hash allocation introduces large performance degradation (probably related to VWA) — "pocke (Masataka Kuwabara) via ruby-core" <ruby-core@...>

Issue #20710 has been reported by pocke (Masataka Kuwabara).

6 messages 2024/09/02

[#119033] [Ruby master Bug#20713] Ruby 3.3.5 triggers a deprecation warning with `require "json"` — "Bo98 (Bo Anderson) via ruby-core" <ruby-core@...>

Issue #20713 has been reported by Bo98 (Bo Anderson).

7 messages 2024/09/04

[#119041] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb` — "Earlopain (A S) via ruby-core" <ruby-core@...>

Issue #20714 has been reported by Earlopain (A S).

31 messages 2024/09/04

[#119074] [Ruby master Bug#20716] Different instance_method behavior in Ruby 2.7 and Ruby 3.x — "natton (Tien Truong) via ruby-core" <ruby-core@...>

Issue #20716 has been reported by natton (Tien Truong).

13 messages 2024/09/06

[#119145] [Ruby master Misc#20728] Propose Eileen Uchitelle as a core committer — "kddnewton (Kevin Newton) via ruby-core" <ruby-core@...>

Issue #20728 has been reported by kddnewton (Kevin Newton).

14 messages 2024/09/12

[#119168] [Ruby master Feature#20738] Removing a specific entry from a hash literal — "ursm (Keita Urashima) via ruby-core" <ruby-core@...>

Issue #20738 has been reported by ursm (Keita Urashima).

16 messages 2024/09/13

[#119199] [Ruby master Bug#20742] Trying to assign to a variable in statement modifier should emit a warning — "esad (Esad Hajdarevic) via ruby-core" <ruby-core@...>

SXNzdWUgIzIwNzQyIGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGVzYWQgKEVzYWQgSGFqZGFyZXZpYyku

7 messages 2024/09/15

[#119208] [Ruby master Bug#20745] IO::Buffer#copy triggers UB when src/dest buffers overlap — "hanazuki (Kasumi Hanazuki) via ruby-core" <ruby-core@...>

Issue #20745 has been reported by hanazuki (Kasumi Hanazuki).

8 messages 2024/09/16

[#119239] [Ruby master Feature#20750] Expose ruby_thread_has_gvl_p in ruby/thread.h — "kbrock (Keenan Brock) via ruby-core" <ruby-core@...>

Issue #20750 has been reported by kbrock (Keenan Brock).

8 messages 2024/09/17

[#119248] [Ruby master Bug#20752] IO::Buffer#slice fails to copy readonly flag, allowing writes into frozen String — "hanazuki (Kasumi Hanazuki) via ruby-core" <ruby-core@...>

Issue #20752 has been reported by hanazuki (Kasumi Hanazuki).

7 messages 2024/09/18

[#119301] [Ruby master Bug#20761] [DOC] `RubyVM::AbstractSyntaxTree.of` examples raise because parser is prism by default — "Earlopain (A S) via ruby-core" <ruby-core@...>

Issue #20761 has been reported by Earlopain (A S).

11 messages 2024/09/26

[#119335] [Ruby master Bug#20770] A *new* pipe operator proposal — "AlexandreMagro (Alexandre Magro) via ruby-core" <ruby-core@...>

Issue #20770 has been reported by AlexandreMagro (Alexandre Magro).

56 messages 2024/09/29

[ruby-core:119144] [Ruby master Bug#20473] Ractor array/hash literals

From: "kddnewton (Kevin Newton) via ruby-core" <ruby-core@...>
Date: 2024-09-12 18:55:32 UTC
List: ruby-core #119144
Issue #20473 has been updated by kddnewton (Kevin Newton).


Truthfully it might not be worth adding these optimizations. It's a lot to maintain in both compilers, and this kind of literal is extremely unlikely to be used with Ractors until other problems with Ractors are solved. I would just as soon not have to maintain this part of the compiler.

Another option would be to put this into the peephole optimizer, which would make it so that you didn't have to update both compilers.

----------------------------------------
Bug #20473: Ractor array/hash literals
https://bugs.ruby-lang.org/issues/20473#change-109731

* Author: kddnewton (Kevin Newton)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
There are many optimizations in place in the compiler to ensure Ruby doesn't overflow the stack when an array or hash literal has many values. For example:

```ruby
puts RubyVM::InstructionSequence.compile(<<~RUBY).disasm
[#{Array.new(512) { |index| index % 128 == 0 ? "\"\#{nil}\"" : "1" }.join(", ")}]
RUBY
```

gives the instructions:

```
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,1564)>
0000 putobject                              ""                        (   1)[Li]
0002 putnil
0003 dup
0004 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
0006 anytostring
0007 concatstrings                          2
0009 newarray                               1
0011 putobject                              [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
0013 concatarray
0014 putobject                              ""
0016 putnil
0017 dup
0018 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
0020 anytostring
0021 concatstrings                          2
0023 newarray                               1
0025 concatarray
0026 putobject                              [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
0028 concatarray
0029 putobject                              ""
0031 putnil
0032 dup
0033 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
0035 anytostring
0036 concatstrings                          2
0038 newarray                               1
0040 concatarray
0041 putobject                              [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
0043 concatarray
0044 putobject                              ""
0046 putnil
0047 dup
0048 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
0050 anytostring
0051 concatstrings                          2
0053 newarray                               1
0055 concatarray
0056 putobject                              [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
0058 concatarray
0059 leave
```

because it is smart enough to group the static elements together and use concatarray. This ensures we never have too many values on the stack.

In Ruby 3.3, this worked for ractors as well. (Adding `# shareable_constant_value: literal` and `A =` to the example above doesn't change anything about the instructions above except adding a couple of `-@` calls and one call to `make_shareable`.

On HEAD, all of these optimizations are now gone. With this:

```ruby
puts RubyVM::InstructionSequence.compile(<<~RUBY).disasm
# shareable_constant_value: literal
A = [#{Array.new(512) { |index| index % 128 == 0 ? "\"\#{nil}\"" : "1" }.join(", ")}]
RUBY
```

code on master, we get:

```
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(2,1568)>
0000 putobject                              RubyVM::FrozenCore        (   2)[Li]
0002 putobject                              ""
0004 putnil
0005 dup
0006 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
0008 anytostring
0009 concatstrings                          2
0011 opt_send_without_block                 <calldata!mid:-@, argc:0, ARGS_SIMPLE>
0013 putobject_INT2FIX_1_
~~~~
0139 putobject_INT2FIX_1_
0140 putobject                              ""
0142 putnil
0143 dup
0144 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
0146 anytostring
0147 concatstrings                          2
0149 opt_send_without_block                 <calldata!mid:-@, argc:0, ARGS_SIMPLE>
0151 putobject_INT2FIX_1_
~~~~
0277 putobject_INT2FIX_1_
0278 putobject                              ""
0280 putnil
0281 dup
0282 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
0284 anytostring
0285 concatstrings                          2
0287 opt_send_without_block                 <calldata!mid:-@, argc:0, ARGS_SIMPLE>
0289 putobject_INT2FIX_1_
~~~~
0415 putobject_INT2FIX_1_
0416 putobject                              ""
0418 putnil
0419 dup
0420 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
0422 anytostring
0423 concatstrings                          2
0425 opt_send_without_block                 <calldata!mid:-@, argc:0, ARGS_SIMPLE>
0427 putobject_INT2FIX_1_
~~~~
0553 putobject_INT2FIX_1_
0554 newarray                               512
0556 opt_send_without_block                 <calldata!mid:make_shareable, argc:1, ARGS_SIMPLE>
0558 dup
0559 putspecialobject                       3
0561 setconstant                            :A
0563 leave
```

where the `~~~~` represents another 128 `putobject_INT2FIX_1_` instructions.

I assume this was done because it used to modify the AST and that got removed. However, I also assume it was not intentional to lose all of these optimizations, as it now means if Ractors are being used that large literals are vulnerable to stack overflows.

Please let me know how to proceed, as I am trying to exactly match behavior in the prism compiler.



-- 
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/


In This Thread