ruby/ext
Jemma Issroff c1ab6ddc9a Transition complex objects to "too complex" shape
When an object becomes "too complex" (in other words it has too many
variations in the shape tree), we transition it to use a "too complex"
shape and use a hash for storing instance variables.

Without this patch, there were rare cases where shape tree growth could
"explode" and cause performance degradation on what would otherwise have
been cached fast paths.

This patch puts a limit on shape tree growth, and gracefully degrades in
the rare case where there could be a factorial growth in the shape tree.

For example:

```ruby
class NG; end

HUGE_NUMBER.times do
  NG.new.instance_variable_set(:"@unique_ivar_#{_1}", 1)
end
```

We consider objects to be "too complex" when the object's class has more
than SHAPE_MAX_VARIATIONS (currently 8) leaf nodes in the shape tree and
the object introduces a new variation (a new leaf node) associated with
that class.

For example, new variations on instances of the following class would be
considered "too complex" because those instances create more than 8
leaves in the shape tree:

```ruby
class Foo; end
9.times { Foo.new.instance_variable_set(":@uniq_#{_1}", 1) }
```

However, the following class is *not* too complex because it only has
one leaf in the shape tree:

```ruby
class Foo
  def initialize
    @a = @b = @c = @d = @e = @f = @g = @h = @i = nil
  end
end
9.times { Foo.new }
``

This case is rare, so we don't expect this change to impact performance
of most applications, but it needs to be handled.

Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
2022-12-15 10:06:04 -08:00
..
-test- Use rb_sprintf instead of deprecated sprintf 2022-11-25 08:51:14 +09:00
bigdecimal [ruby/bigdecimal] Bump version to 3.1.3 2022-12-05 10:44:30 +00:00
cgi/escape [ruby/cgi] Implement CGI.url_encode and CGI.url_decode 2022-08-16 19:12:03 +09:00
continuation [Feature #18249] Update dependencies 2022-02-22 09:55:21 -05:00
coverage Update dependencies 2022-12-06 12:37:23 -08:00
date [ruby/date] Fixed wrong minimum version of Ruby 2022-12-14 07:56:09 +00:00
digest [ruby/digest] Bump version to 3.1.1 2022-12-05 05:56:58 +00:00
erb/escape [ruby/erb] Skip using the extension for truffleruby as well 2022-11-27 06:30:48 +00:00
etc [ruby/etc] Bump version to 1.4.2 2022-12-09 05:57:49 +00:00
fcntl [ruby/fcntl] Bump version to 1.0.2 2022-12-05 06:09:41 +00:00
fiddle Merge fiddle-1.1.1 2022-12-09 16:36:22 +09:00
io [ruby/io-nonblock] Bump version to 0.2.0 2022-12-05 06:22:15 +00:00
json Merge json-2.6.3 2022-12-09 16:36:22 +09:00
monitor [Feature #18249] Update dependencies 2022-02-22 09:55:21 -05:00
nkf [ruby/nkf] Bump version to 0.1.2 2022-12-05 06:51:37 +00:00
objspace Transition complex objects to "too complex" shape 2022-12-15 10:06:04 -08:00
openssl [ruby/openssl] [DOC] Remove duplicate doc 2022-12-13 19:55:18 +09:00
pathname [ruby/pathname] Bump version to 0.2.1 2022-12-05 16:33:43 +09:00
psych [ruby/psych] Bump version to 5.0.1 2022-12-08 02:08:25 +00:00
pty Transition shape when object's capacity changes 2022-11-10 10:11:34 -05:00
racc/cparse [Feature #18249] Update dependencies 2022-02-22 09:55:21 -05:00
rbconfig/sizeof [Feature #18249] Update dependencies 2022-02-22 09:55:21 -05:00
readline [ruby/readline-ext] Bump version to 0.1.5 2022-12-14 05:54:06 +00:00
ripper Introduce encoding check macro 2022-12-02 01:31:27 +09:00
rubyvm Added depend files 2019-07-14 01:31:29 +09:00
socket Remove require 'io/wait' where it's no longer necessary. (#6932) 2022-12-15 11:37:01 +13:00
stringio Merge stringio-3.0.4 2022-12-09 16:36:22 +09:00
strscan Merge strscan-3.0.5 2022-12-09 16:36:22 +09:00
syslog [ruby/syslog] Bump version to 0.1.1 2022-12-14 06:18:10 +00:00
win32 Expand tabs [ci skip] 2022-07-21 09:42:04 -07:00
win32ole [ruby/win32ole] Bump version to 1.8.9 2022-12-05 08:22:51 +00:00
zlib [ruby/zlib] Bump version to 3.0.0 2022-12-05 08:26:21 +00:00
.document Remove unnecessary files from .document 2020-12-20 16:00:13 +09:00
extmk.rb Use class methods of File over Kernel.open and IO.read 2022-11-21 22:16:49 +09:00
Setup Removed sdbm entries from toolchanins 2020-06-19 08:26:47 +09:00
Setup.atheos Removed sdbm entries from toolchanins 2020-06-19 08:26:47 +09:00
Setup.nt Removed sdbm entries from toolchanins 2020-06-19 08:26:47 +09:00