Skip to content

Commit fb4dcb4

Browse files
committed
The form 'expr rescue {simple}' where simple is immediate values or
values which do not cause any method execution (or side-effects) will omit generating backtraces since there is no way to get access to $!. This improves performance of these simple catch-all forms by ~48x. Note: a follow-on commit can fix 'begin; expr; rescue; {simple}; end' later. It is much less common and not as ripe a target. BEFORE: system ~/work/jruby master 814% jruby --dev ../snippets/bench2.rb Calculating ------------------------------------- begin moo rescue nil 89.000 i/100ms moo rescue nil (single) 91.000 i/100ms ------------------------------------------------- begin moo rescue nil 956.234 (± 4.4%) i/s - 9.612k moo rescue nil (single) 955.879 (± 4.8%) i/s - 9.555k system ~/work/jruby master 815% jruby -X-C ../snippets/bench2.rb Calculating ------------------------------------- begin moo rescue nil 100.000 i/100ms moo rescue nil (single) 106.000 i/100ms ------------------------------------------------- begin moo rescue nil 1.085k (± 5.2%) i/s - 10.900k moo rescue nil (single) 1.072k (± 5.5%) i/s - 10.706k system ~/work/jruby master 816% jruby ../snippets/bench2.rb Calculating ------------------------------------- begin moo rescue nil 104.000 i/100ms moo rescue nil (single) 105.000 i/100ms ------------------------------------------------- begin moo rescue nil 1.074k (± 5.7%) i/s - 10.712k moo rescue nil (single) 1.089k (± 5.0%) i/s - 10.920k system ~/work/jruby master 817% jruby -Xcompile.invokedynamic=true ../snippets/bench2.rb Calculating ------------------------------------- begin moo rescue nil 112.000 i/100ms moo rescue nil (single) 122.000 i/100ms ------------------------------------------------- begin moo rescue nil 1.275k (± 5.4%) i/s - 12.768k moo rescue nil (single) 1.253k (± 4.7%) i/s - 12.566k AFTER: system ~/work/jruby master * 820% jruby --dev ../snippets/bench2.rb Calculating ------------------------------------- begin moo rescue nil 89.000 i/100ms moo rescue nil (single) 1.199k i/100ms ------------------------------------------------- begin moo rescue nil 921.217 (± 5.1%) i/s - 9.256k moo rescue nil (single) 12.833k (± 4.9%) i/s - 128.293k system ~/work/jruby master * 821% jruby -X-C ../snippets/bench2.rb Calculating ------------------------------------- begin moo rescue nil 100.000 i/100ms moo rescue nil (single) 3.037k i/100ms ------------------------------------------------- begin moo rescue nil 1.031k (± 6.2%) i/s - 10.300k moo rescue nil (single) 35.393k (± 5.5%) i/s - 355.329k system ~/work/jruby master * 822% jruby ../snippets/bench2.rb Calculating ------------------------------------- begin moo rescue nil 100.000 i/100ms moo rescue nil (single) 4.725k i/100ms ------------------------------------------------- begin moo rescue nil 1.119k (± 4.6%) i/s - 11.200k moo rescue nil (single) 52.318k (± 5.8%) i/s - 524.475k system ~/work/jruby master * 823% jruby -Xcompile.invokedynamic=true ../snippets/bench2.rb Calculating ------------------------------------- begin moo rescue nil 106.000 i/100ms moo rescue nil (single) 5.076k i/100ms ------------------------------------------------- begin moo rescue nil 1.176k (± 5.5%) i/s - 11.766k moo rescue nil (single) 49.198k (± 5.5%) i/s - 492.372k MRI 2.2.2: system ~/work/jruby master * 824% mri22 ../snippets/bench2.rb Calculating ------------------------------------- begin moo rescue nil 2.771k i/100ms moo rescue nil (single) 2.707k i/100ms ------------------------------------------------- begin moo rescue nil 28.586k (± 5.2%) i/s - 285.413k moo rescue nil (single) 28.470k (± 4.2%) i/s - 284.235k
1 parent 55be66e commit fb4dcb4

29 files changed

+157
-29
lines changed

core/src/main/java/org/jruby/ast/BignumNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
/**
4242
* Represents a big integer literal.
4343
*/
44-
public class BignumNode extends NumericNode {
44+
public class BignumNode extends NumericNode implements SideEffectFree {
4545
private BigInteger value;
4646

4747
public BignumNode(ISourcePosition position, BigInteger value) {

core/src/main/java/org/jruby/ast/ClassVarNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/**
4141
* Access to a class variable.
4242
*/
43-
public class ClassVarNode extends Node implements INameNode {
43+
public class ClassVarNode extends Node implements INameNode, SideEffectFree {
4444
private String name;
4545

4646
public ClassVarNode(ISourcePosition position, String name) {

core/src/main/java/org/jruby/ast/ComplexNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* @author enebo
1616
*/
17-
public class ComplexNode extends NumericNode {
17+
public class ComplexNode extends NumericNode implements SideEffectFree {
1818
private NumericNode y;
1919

2020
public ComplexNode(ISourcePosition position, NumericNode y) {

core/src/main/java/org/jruby/ast/FalseNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/**
4141
* Represents a false literal.
4242
*/
43-
public class FalseNode extends Node implements INameNode {
43+
public class FalseNode extends Node implements INameNode, SideEffectFree {
4444
public FalseNode(ISourcePosition position) {
4545
super(position, false);
4646
}

core/src/main/java/org/jruby/ast/FileNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
/**
3535
* Represents __FILE__ nodes
3636
*/
37-
public class FileNode extends StrNode {
37+
public class FileNode extends StrNode implements SideEffectFree {
3838
public FileNode(ISourcePosition position, ByteList value) {
3939
super(position, value);
4040
}

core/src/main/java/org/jruby/ast/FixnumNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/**
4141
* Represents an integer literal.
4242
*/
43-
public class FixnumNode extends NumericNode implements ILiteralNode {
43+
public class FixnumNode extends NumericNode implements ILiteralNode, SideEffectFree {
4444
private long value;
4545

4646
public FixnumNode(ISourcePosition position, long value) {

core/src/main/java/org/jruby/ast/FloatNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/**
4141
* Represents a float literal.
4242
*/
43-
public class FloatNode extends NumericNode implements ILiteralNode {
43+
public class FloatNode extends NumericNode implements ILiteralNode, SideEffectFree {
4444
private double value;
4545

4646
public FloatNode(ISourcePosition position, double value) {

core/src/main/java/org/jruby/ast/GlobalVarNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/**
4141
* access to a global variable.
4242
*/
43-
public class GlobalVarNode extends Node implements INameNode {
43+
public class GlobalVarNode extends Node implements INameNode, SideEffectFree {
4444
private String name;
4545

4646
public GlobalVarNode(ISourcePosition position, String name) {

core/src/main/java/org/jruby/ast/InstVarNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
/**
4242
* Represents an instance variable accessor.
4343
*/
44-
public class InstVarNode extends Node implements INameNode {
44+
public class InstVarNode extends Node implements INameNode, SideEffectFree {
4545
private String name;
4646

4747
public InstVarNode(ISourcePosition position, String name) {

core/src/main/java/org/jruby/ast/LocalVarNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/**
4141
* Access a local variable
4242
*/
43-
public class LocalVarNode extends Node implements INameNode, IScopedNode {
43+
public class LocalVarNode extends Node implements INameNode, IScopedNode, SideEffectFree {
4444
// The name of the variable
4545
private String name;
4646

0 commit comments

Comments
 (0)