summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2023-10-24 12:43:22 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2023-10-24 14:23:17 -0700
commitd8cb827f39d4c72d2a79e40371ba2a4fb3e95b28 (patch)
tree9e3caf7e4963712f2aca069e276bc44845a3cebf
parent33bebee13aedb9f8a0d43cc6921910a690e6f73e (diff)
Remove SHAPE_MAX_NUM_IVS
There is no longer a limit on the number of IVs you can store. SHAPE_MAX_NUM_IVS was used to work around the IV10K problem (the well known problem where setting 10k instance variables in a row would be too slow). The redblack tree works well at any shape depth, even depths greater than 80, and solves the IV10K problem.
-rw-r--r--shape.c1
-rw-r--r--shape.h1
-rw-r--r--test/ruby/test_shapes.rb12
3 files changed, 7 insertions, 7 deletions
diff --git a/shape.c b/shape.c
index eecae3ee64..a2e2e4446d 100644
--- a/shape.c
+++ b/shape.c
@@ -1182,7 +1182,6 @@ Init_shape(void)
rb_define_const(rb_cShape, "SPECIAL_CONST_SHAPE_ID", INT2NUM(SPECIAL_CONST_SHAPE_ID));
rb_define_const(rb_cShape, "OBJ_TOO_COMPLEX_SHAPE_ID", INT2NUM(OBJ_TOO_COMPLEX_SHAPE_ID));
rb_define_const(rb_cShape, "SHAPE_MAX_VARIATIONS", INT2NUM(SHAPE_MAX_VARIATIONS));
- rb_define_const(rb_cShape, "SHAPE_MAX_NUM_IVS", INT2NUM(SHAPE_MAX_NUM_IVS));
rb_define_singleton_method(rb_cShape, "transition_tree", shape_transition_tree, 0);
rb_define_singleton_method(rb_cShape, "find_by_id", rb_shape_find_by_id, 1);
diff --git a/shape.h b/shape.h
index 3f78551c54..0529dc45b6 100644
--- a/shape.h
+++ b/shape.h
@@ -33,7 +33,6 @@ typedef uint16_t redblack_id_t;
# define SHAPE_FLAG_SHIFT ((SIZEOF_VALUE * 8) - SHAPE_ID_NUM_BITS)
# define SHAPE_MAX_VARIATIONS 8
-# define SHAPE_MAX_NUM_IVS 80
# define MAX_SHAPE_ID (SHAPE_BUFFER_SIZE - 1)
# define INVALID_SHAPE_ID SHAPE_MASK
diff --git a/test/ruby/test_shapes.rb b/test/ruby/test_shapes.rb
index 591fdbe4a3..7849ca546b 100644
--- a/test/ruby/test_shapes.rb
+++ b/test/ruby/test_shapes.rb
@@ -5,6 +5,8 @@ require 'json'
# These test the functionality of object shapes
class TestShapes < Test::Unit::TestCase
+ MANY_IVS = 80
+
class IVOrder
def expected_ivs
%w{ @a @b @c @d @e @f @g @h @i @j @k }
@@ -149,7 +151,7 @@ class TestShapes < Test::Unit::TestCase
def test_too_many_ivs_on_class
obj = Class.new
- (RubyVM::Shape::SHAPE_MAX_NUM_IVS + 1).times do
+ (MANY_IVS + 1).times do
obj.instance_variable_set(:"@a#{_1}", 1)
end
@@ -159,10 +161,10 @@ class TestShapes < Test::Unit::TestCase
def test_removing_when_too_many_ivs_on_class
obj = Class.new
- (RubyVM::Shape::SHAPE_MAX_NUM_IVS + 2).times do
+ (MANY_IVS + 2).times do
obj.instance_variable_set(:"@a#{_1}", 1)
end
- (RubyVM::Shape::SHAPE_MAX_NUM_IVS + 2).times do
+ (MANY_IVS + 2).times do
obj.remove_instance_variable(:"@a#{_1}")
end
@@ -172,10 +174,10 @@ class TestShapes < Test::Unit::TestCase
def test_removing_when_too_many_ivs_on_module
obj = Module.new
- (RubyVM::Shape::SHAPE_MAX_NUM_IVS + 2).times do
+ (MANY_IVS + 2).times do
obj.instance_variable_set(:"@a#{_1}", 1)
end
- (RubyVM::Shape::SHAPE_MAX_NUM_IVS + 2).times do
+ (MANY_IVS + 2).times do
obj.remove_instance_variable(:"@a#{_1}")
end