Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make the SHAPE_TOO_COMPLEX performance warning more actionable #9275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions shape.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,10 @@ rb_shape_get_next(rb_shape_t *shape, VALUE obj, ID id)
if (RCLASS_EXT(klass)->variation_count >= SHAPE_MAX_VARIATIONS) {
rb_category_warn(
RB_WARN_CATEGORY_PERFORMANCE,
"Maximum shapes variations (%d) reached by %"PRIsVALUE", instance variables accesses will be slower.",
SHAPE_MAX_VARIATIONS,
rb_class_path(klass)
"The class %"PRIsVALUE" reached %d shape variations, instance variables accesses will be slower and memory usage increased.\n"
"It is recommended to define instance variable in a consistent order, for instance by eagerly defining them all in the `initialize` method.",
Copy link
Member

@eregon eregon Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but backquotes seem rare in Ruby exception/warning messages, here I think #initialize would be better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rb_class_path(klass),
SHAPE_MAX_VARIATIONS
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/ruby/test_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def test_check_to_integer
end

def test_max_shape_variation_with_performance_warnings
assert_in_out_err([], <<-INPUT, %w(), /Maximum shapes variations \(8\) reached by Foo, instance variables accesses will be slower\.$/)
assert_in_out_err([], <<-INPUT, %w(), /The class Foo reached 8 shape variations, instance variables accesses will be slower and memory usage increased/)
$VERBOSE = false
Warning[:performance] = true

Expand Down