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.
This commit is contained in:
Aaron Patterson 2023-10-24 12:43:22 -07:00 committed by Aaron Patterson
parent 33bebee13a
commit d8cb827f39
3 changed files with 7 additions and 7 deletions

View File

@ -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);

View File

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

View File

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