<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ruby.git/test/ruby/test_object_id.rb, branch v4.0.2</title>
<subtitle>The Ruby Programming Language</subtitle>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/'/>
<entry>
<title>Struct: keep direct reference to IMEMO/fields when space allows</title>
<updated>2025-08-06T15:07:49+00:00</updated>
<author>
<name>Jean Boussier</name>
<email>jean.boussier@gmail.com</email>
</author>
<published>2025-08-06T12:46:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=f3206cc79bec2fd852e81ec56de59f0a67ab32b7'/>
<id>f3206cc79bec2fd852e81ec56de59f0a67ab32b7</id>
<content type='text'>
It's not rare for structs to have additional ivars, hence are one
of the most common, if not the most common type in the `gen_fields_tbl`.

This can cause Ractor contention, but even in single ractor mode
means having to do a hash lookup to access the ivars, and increase
GC work.

Instead, unless the struct is perfectly right sized, we can store
a reference to the associated IMEMO/fields object right after the
last struct member.

```
compare-ruby: ruby 3.5.0dev (2025-08-06T12:50:36Z struct-ivar-fields-2 9a30d141a1) +PRISM [arm64-darwin24]
built-ruby: ruby 3.5.0dev (2025-08-06T12:57:59Z struct-ivar-fields-2 2ff3ec237f) +PRISM [arm64-darwin24]
warming up.....

|                      |compare-ruby|built-ruby|
|:---------------------|-----------:|---------:|
|member_reader         |    590.317k|  579.246k|
|                      |       1.02x|         -|
|member_writer         |    543.963k|  527.104k|
|                      |       1.03x|         -|
|member_reader_method  |    213.540k|  213.004k|
|                      |       1.00x|         -|
|member_writer_method  |    192.657k|  191.491k|
|                      |       1.01x|         -|
|ivar_reader           |    403.993k|  569.915k|
|                      |           -|     1.41x|
```

Co-Authored-By: Étienne Barrié &lt;etienne.barrie@gmail.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
It's not rare for structs to have additional ivars, hence are one
of the most common, if not the most common type in the `gen_fields_tbl`.

This can cause Ractor contention, but even in single ractor mode
means having to do a hash lookup to access the ivars, and increase
GC work.

Instead, unless the struct is perfectly right sized, we can store
a reference to the associated IMEMO/fields object right after the
last struct member.

```
compare-ruby: ruby 3.5.0dev (2025-08-06T12:50:36Z struct-ivar-fields-2 9a30d141a1) +PRISM [arm64-darwin24]
built-ruby: ruby 3.5.0dev (2025-08-06T12:57:59Z struct-ivar-fields-2 2ff3ec237f) +PRISM [arm64-darwin24]
warming up.....

|                      |compare-ruby|built-ruby|
|:---------------------|-----------:|---------:|
|member_reader         |    590.317k|  579.246k|
|                      |       1.02x|         -|
|member_writer         |    543.963k|  527.104k|
|                      |       1.03x|         -|
|member_reader_method  |    213.540k|  213.004k|
|                      |       1.00x|         -|
|member_writer_method  |    192.657k|  191.491k|
|                      |       1.01x|         -|
|ivar_reader           |    403.993k|  569.915k|
|                      |           -|     1.41x|
```

Co-Authored-By: Étienne Barrié &lt;etienne.barrie@gmail.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>variable.c: avoid out of bound write in `generic_field_set`</title>
<updated>2025-06-21T13:40:40+00:00</updated>
<author>
<name>Jean Boussier</name>
<email>jean.boussier@gmail.com</email>
</author>
<published>2025-06-21T12:43:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=edbd9ed46842b8cd811fba45a373bb39ee155bfb'/>
<id>edbd9ed46842b8cd811fba45a373bb39ee155bfb</id>
<content type='text'>
[Bug #21445]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[Bug #21445]
</pre>
</div>
</content>
</entry>
<entry>
<title>Remove test_object_id_race_free_with_stress_compact</title>
<updated>2025-06-14T05:55:43+00:00</updated>
<author>
<name>Jean Boussier</name>
<email>jean.boussier@gmail.com</email>
</author>
<published>2025-06-14T05:55:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=74cdf8727e6eb2f958a8516c44fcb1d429a3451c'/>
<id>74cdf8727e6eb2f958a8516c44fcb1d429a3451c</id>
<content type='text'>
This test was written for another implementation of `#object_id`
which had complex interations with GC, that's not the case of
the implementation that was actually merged.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This test was written for another implementation of `#object_id`
which had complex interations with GC, that's not the case of
the implementation that was actually merged.
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix a race condition in object_id for shareable objects</title>
<updated>2025-06-13T16:27:52+00:00</updated>
<author>
<name>Jean Boussier</name>
<email>jean.boussier@gmail.com</email>
</author>
<published>2025-06-13T12:25:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=e22fc73c66b478a19930788b7d23c6ea48b4bdec'/>
<id>e22fc73c66b478a19930788b7d23c6ea48b4bdec</id>
<content type='text'>
If an object is shareable and has no capacity left, it isn't
safe to store the object ID in fields as it requires an object
resize which can't be done unless all field reads are synchronized.

In this very specific case we create the object_id in advance,
before the object is made shareable.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
If an object is shareable and has no capacity left, it isn't
safe to store the object ID in fields as it requires an object
resize which can't be done unless all field reads are synchronized.

In this very specific case we create the object_id in advance,
before the object is made shareable.
</pre>
</div>
</content>
</entry>
<entry>
<title>shape.c: match capacity growth with T_OBJECT embedded sizes</title>
<updated>2025-06-06T11:37:03+00:00</updated>
<author>
<name>Jean Boussier</name>
<email>jean.boussier@gmail.com</email>
</author>
<published>2025-06-06T10:16:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=2b810ac595664423e612964616068ad95d9d9e5e'/>
<id>2b810ac595664423e612964616068ad95d9d9e5e</id>
<content type='text'>
This helps with getting with of `SHAPE_T_OBJECT`, by ensuring
that transitions will have capacities that match the next embed size.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This helps with getting with of `SHAPE_T_OBJECT`, by ensuring
that transitions will have capacities that match the next embed size.
</pre>
</div>
</content>
</entry>
<entry>
<title>test_object_id.rb: use better randomness</title>
<updated>2025-05-12T07:49:59+00:00</updated>
<author>
<name>Jean Boussier</name>
<email>jean.boussier@gmail.com</email>
</author>
<published>2025-05-12T07:49:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=131ba059cad0cff223842a739b2bc87425613b49'/>
<id>131ba059cad0cff223842a739b2bc87425613b49</id>
<content type='text'>
When the test is repeated 20 or more times in the same process
it's not that unlikely for `rand(100_000)` to return the same thing
twice, causing `TestObjectIdTooComplexClass` to fail.

```
  1) Failure:
TestObjectIdTooComplexClass#test_dup_with_id_and_ivar [/tmp/ruby/src/trunk-repeat20-asserts/test/ruby/test_object_id.rb:172]:
Expected #&lt;struct RubyVM::Shape
 id=6783,
 parent_id=6774,
 edge_name=:@___26417,
 next_field_index=2,
 heap_index=0,
 type=1,
 capacity=7&gt; to be too_complex?.
```
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When the test is repeated 20 or more times in the same process
it's not that unlikely for `rand(100_000)` to return the same thing
twice, causing `TestObjectIdTooComplexClass` to fail.

```
  1) Failure:
TestObjectIdTooComplexClass#test_dup_with_id_and_ivar [/tmp/ruby/src/trunk-repeat20-asserts/test/ruby/test_object_id.rb:172]:
Expected #&lt;struct RubyVM::Shape
 id=6783,
 parent_id=6774,
 edge_name=:@___26417,
 next_field_index=2,
 heap_index=0,
 type=1,
 capacity=7&gt; to be too_complex?.
```
</pre>
</div>
</content>
</entry>
<entry>
<title>Allow T_CLASS and generic types to be too_complex</title>
<updated>2025-05-11T17:35:58+00:00</updated>
<author>
<name>Jean Boussier</name>
<email>jean.boussier@gmail.com</email>
</author>
<published>2025-05-11T16:47:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=f2e5f6dbb605960b69ddced5503a18639aa29e8e'/>
<id>f2e5f6dbb605960b69ddced5503a18639aa29e8e</id>
<content type='text'>
The intial complex shape implementation never allowed objects
other than T_OBJECT to become too complex, unless we run out of
shapes.

I don't see any reason to prevent that.

Ref: https://github.com/ruby/ruby/pull/6931
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The intial complex shape implementation never allowed objects
other than T_OBJECT to become too complex, unless we run out of
shapes.

I don't see any reason to prevent that.

Ref: https://github.com/ruby/ruby/pull/6931
</pre>
</div>
</content>
</entry>
<entry>
<title>Move `object_id` in object fields.</title>
<updated>2025-05-08T05:58:05+00:00</updated>
<author>
<name>Jean Boussier</name>
<email>jean.boussier@gmail.com</email>
</author>
<published>2025-04-21T07:16:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=f48e45d1e9c4412d5f3ee49241d0b9359651ce7c'/>
<id>f48e45d1e9c4412d5f3ee49241d0b9359651ce7c</id>
<content type='text'>
And get rid of the `obj_to_id_tbl`

It's no longer needed, the `object_id` is now stored inline
in the object alongside instance variables.

We still need the inverse table in case `_id2ref` is invoked, but
we lazily build it by walking the heap if that happens.

The `object_id` concern is also no longer a GC implementation
concern, but a generic implementation.

Co-Authored-By: Matt Valentine-House &lt;matt@eightbitraptor.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
And get rid of the `obj_to_id_tbl`

It's no longer needed, the `object_id` is now stored inline
in the object alongside instance variables.

We still need the inverse table in case `_id2ref` is invoked, but
we lazily build it by walking the heap if that happens.

The `object_id` concern is also no longer a GC implementation
concern, but a generic implementation.

Co-Authored-By: Matt Valentine-House &lt;matt@eightbitraptor.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
