summaryrefslogtreecommitdiff
path: root/shape.c
diff options
context:
space:
mode:
authorJean Boussier <byroot@ruby-lang.org>2023-04-13 12:11:14 +0200
committerJean Boussier <jean.boussier@gmail.com>2023-04-13 16:36:17 +0200
commitac123f167a364c3d7a43eca78d564e41f6dbb91e (patch)
tree76c34bd65a5942ce9ef38e1753943e83082f08ee /shape.c
parent854baee2c936006d7f38ebb27ee577c00afc6249 (diff)
downloadruby-ac123f167a364c3d7a43eca78d564e41f6dbb91e.tar.gz
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`
Diffstat (limited to 'shape.c')
-rw-r--r--shape.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/shape.c b/shape.c
index 36d1adb7d9..05e5d76f60 100644
--- a/shape.c
+++ b/shape.c
@@ -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)
+ );
+ }
+ }
}
}