diff options
author | Jean Boussier <byroot@ruby-lang.org> | 2023-04-13 12:11:14 +0200 |
---|---|---|
committer | Jean Boussier <jean.boussier@gmail.com> | 2023-04-13 16:36:17 +0200 |
commit | ac123f167a364c3d7a43eca78d564e41f6dbb91e (patch) | |
tree | 76c34bd65a5942ce9ef38e1753943e83082f08ee /shape.c | |
parent | 854baee2c936006d7f38ebb27ee577c00afc6249 (diff) |
Emit a performance warning when a class reached max variations
[Feature #19538]
This new `peformance` warning category is disabled by default.
It needs to be specifically enabled via `-W:performance` or `Warning[:performance] = true`
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7708
Diffstat (limited to 'shape.c')
-rw-r--r-- | shape.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -7,6 +7,7 @@ #include "internal/gc.h" #include "internal/symbol.h" #include "internal/variable.h" +#include "internal/error.h" #include "variable.h" #include <stdbool.h> @@ -407,6 +408,16 @@ rb_shape_get_next(rb_shape_t* shape, VALUE obj, ID id) if (variation_created) { RCLASS_EXT(klass)->variation_count++; + if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_PERFORMANCE)) { + if (RCLASS_EXT(klass)->variation_count >= SHAPE_MAX_VARIATIONS) { + rb_category_warning( + RB_WARN_CATEGORY_PERFORMANCE, + "Maximum shapes variations (%d) reached by %"PRIsVALUE", instance variables accesses will be slower.", + SHAPE_MAX_VARIATIONS, + rb_class_path(klass) + ); + } + } } } |