Skip to content

Commit b5be3b4

Browse files
committed
Add performance warning for Primitive.regexp_compile
1 parent 5ba3731 commit b5be3b4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/java/org/truffleruby/core/regexp/RegexpNodes.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.truffleruby.core.string.RubyString;
3333
import org.truffleruby.core.symbol.RubySymbol;
3434
import org.truffleruby.annotations.Visibility;
35+
import org.truffleruby.language.NotOptimizedWarningNode;
3536
import org.truffleruby.language.control.DeferredRaiseException;
3637
import org.truffleruby.language.control.RaiseException;
3738
import org.truffleruby.language.library.RubyStringLibrary;
@@ -199,7 +200,10 @@ static RubyRegexp fastCompiling(Object pattern, int options,
199200
RubyRegexp slowCompiling(Object pattern, int options,
200201
@Cached InlinedBranchProfile errorProfile,
201202
@Cached @Shared TruffleString.AsTruffleStringNode asTruffleStringNode,
202-
@Cached @Shared RubyStringLibrary libPattern) {
203+
@Cached @Shared RubyStringLibrary libPattern,
204+
@Cached NotOptimizedWarningNode notOptimizedWarningNode) {
205+
notOptimizedWarningNode.warn(
206+
"unbounded creation of regexps causes deoptimization loops which hurts performance significantly, avoid creating regexps dynamically where possible or cache them to fix this");
203207
return compile(pattern, options, this, libPattern, asTruffleStringNode, errorProfile);
204208
}
205209

0 commit comments

Comments
 (0)